Problem with reading pfm image

I’m trying to load disparity images from into pytorch tensors for my network.
They are stored in PFM format and this code is provided for reading them.
It returns a numpy array, so i just used torch.from_numpy(), but i get

RuntimeError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.

Does anyone know a workaround for this or an ETA for negative strides support?

The workaround would be to call .as_c_contiguous_array() (I think that’s the method name – maybe you need .clone() instead though) in numpy immediately before giving it to .from_numpy()

1 Like

Thanks, numpy.ascontiguousarray() worked.

I also discovered that the negative strides are caused by an upside-down flipping of the array (in the code used to read the pfm image), so deleting that line and flipping the pytorch tensor with an index_select() works too.

a = readPFM(file)
a = np.ascontiguousarray(a)
a = torch.from_numpy(a)

still doesn’t work?