onnx2pytorch icon indicating copy to clipboard operation
onnx2pytorch copied to clipboard

UserWarning: NumPy array is not writeable

Open jfulem opened this issue 3 years ago • 2 comments

When converting an onnx model to pytorch I'm getting this warning:

UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor

It's caused by a method load_params() in onnx2pytorch\convert\layer.py and line 138 in onnx2pytorch\convert\model.py.

For example when this torch.from_numpy(numpy_helper.to_array(tensor)) is modified to use the numpy copy torch.from_numpy(np.copy(numpy_helper.to_array(tensor))) then all the warnings are gone.

Please, can you comment on this?

jfulem avatar Feb 15 '22 22:02 jfulem

I'm getting this as well. I'm only loading these so that I can modify the weights before exporting them as an onnx model again. Should I be concerned about this?

mike-burl avatar Dec 02 '22 19:12 mike-burl

Probably not

jfulem avatar Dec 02 '22 20:12 jfulem

This was fixed in v0.5.2

Talmaj avatar Nov 01 '25 23:11 Talmaj