Issues with serializing and deserializing C++ tensors (stringstream -> string - char* -> stringstream)

You might want to open the stream in binary mode as in:

std::ostringstream oss(std::ios::binary);
torch::save(t, oss);

I don’t remember the details anymore, but I had similar issues in the past related to null characters in the string that were fixed by opening the stream in binary mode.

1 Like