I am trying to use the hidden layer result to generate heatmap with libtorch jit
The code snippet is shown below:
The return value of the model should be two parameters, such as hidden_output and predict_result.
From some materials online, it seems that
toTensorList() function is an appropriate choice for multiple return values based on the discussion at convert-c10-ivalue-to-tensor-or-tuple-failed.
I try to use
toTensorList() but I came across the “std ambiguous” problem.
This error is resolved by adding the
":: " to the beginning of
"std::" based on the discussion at compiler-report-std-ambiguous-symbol-error-under-visual-c-2017
However, the exception problem keeps occurring which is very confused to me. Is there any solution to this problem?
Thank you very much for your attention to this problem.
Please check thr following things:
- Are you mixing the Debug and Release configuration?
- Have you copied all the DLLs in LibTorch to the location of your executable?
- Have you moved the model to the desired device before calculation?
btw, which version of libtorch are you using?
Thank you very much for your reply @peterjc123 !
1. Are you mixing the Debug and Release configuration?
No. I have separate libtorch for Debug and Release configuration. The loading model code snippet runs well, which I think there is no configuration error.
2. Have you copied all the DLLs in LibTorch to the location of your executable?
Yes, I have all the DLL files copied.
3. Have you moved the model to the desired device before calculation?
The model is training on the GPU.
And I convert all the tensor data to GPU before calling forward() function.
4.which version of libtorch are you using?
The libtorch version is the latest 1.4. And I use pyTorch 1.4 for training the network.
My forward() function in python code returns as shown below:
Is this the proper way to return multiple values? Does this work in the JIT tracing for the C++ library?
After I checked each variable’s value, I find the return value of the function is tuple instead of tensorlist.
The method is changed to
toTuple() instead of
Then the problem is solved.
I think I just misunderstand the answer at convert_ivalue_to_tensor_or_tuple.