Closed JaimeParker closed 4 months ago
the way I set observation in c++ is:
std::vector<double> values = // 26 double data
torch::Tensor obs_tensor_data = torch::from_blob(values.data(), {1, 26});
std::vector<torch::jit::IValue> obs_tensor;
obs_tensor.emplace_back(obs_tensor_data);
return obs_tensor;
my num_obs is 26
I shall put the pt file on google drive, and the obs is a 1*26 array
[0. 0. 0. 0. 0. 0.
3. 1. 0.8 0. 0. 2.
0. 0. 3. 0. 0. 1.
0. 0. 1. 0. 0. 2.
3. 1.57079633]
For the clipping, in the doc "The following returns normalized actions and doesn’t include the post-processing step that is done with continuous actions (clip or unscale the action to the correct space)."
For the observation, you should give "all zeros" and "all ones" a try (that's easier to make sure they are the same in python/c++). For the rest, I don't know, if the jit/onnx export/load worked in python, then it might be an error in pytorch? (or a mismatch between pytorch versions)
@araffin fixed, should use float
in c++ instead of double
.
in the get_obs
function in c++:
std::vector<double> values = { 26 numbers };
torch::Tensor obs_tensor_data = torch::from_blob(values.data(), {1, 26});
std::vector<torch::jit::IValue> obs_tensor;
obs_tensor.emplace_back(obs_tensor_data);
// std::vector<torch::jit::IValue> obs_tensor;
// obs_tensor.emplace_back(torch::ones({1, 32}));
return obs_tensor;
the data type should be float
, which is
std::vector<float> values;
shall close this one and thanks for your help!
❓ Question
I trained a model using PPO, then converted it to
onnx
, to.pt
based on doc export . However, when I used c++ to load this model and testing, it got totally different prediction, and changes each time I run my c++ program when the observation was fixed.Here is my
onnx_utils.py
, this is for converting a model trained by PPO toonnx
andpt
then saving them.mention that
is my self-designed code, it only provided some saving and parameters loading work.
After saving the onnx model and pt model, I tried do prediction using both python and c++. First is the python script:
output is:
My action space is between $[-1, 1]$ , I don't know why onnx output and pt output exceeded that. But it seems would be normal if using a
np.clip
.For c++, its weird. First is the class.
second is my main function
outcomes:
run it again
and again
I'm sure that I was using the same model and observation!
How to fix it, thanks in advance!
Checklist