I have observed that strides of input and output tensors (just before and after network inference) are different. This behavior can be observed both in python and C++. I am not sure whether this is an inherent feature or a bug.
Example:
input_Tensor size: [1, 3, 256, 256]
input_Tensor strides: [256x256x3, 256x256, 256, 1]
output_Tensor size: [1, 3, 256, 256]
output_Tensor strides: [256x256x3, 1 , 256x3 , 3]
This behavior is specially problematic when in C++ (libtorch) we try to set input Tensor data from a buffer like this:
torch::Tensor input_Tensor = torch::from_blob(input_buffer,{1,3,256,256},torch::kFloat);

and after inference try to copy output Tensor data to a buffer like this:
memcpy(output_buffer, (float*)output_Tensor.data_ptr(), 256*256*3*sizeof(float));

So, if strides of input_Tensor and output_Tensor differs like in above example, we will get wrong data filled in output_buffer. One way to resolve this is to make output_Tensor contiguous before doing memcpy.