I had to downgrade pandas 2.2.0 to 2.1.4
Answer from david serero on Stack OverflowData: "Cannot convert numpy.ndarray to numpy.ndarray" Error on Simple RowBasedFileDatasink Implementation
TypeError: Cannot convert numpy.ndarray to numpy.ndarray
TypeError: Cannot convert numpy.ndarray to numpy.ndarray when running the code
TypeError: can't convert np.ndarray of type numpy.object_.
Hey Guys, I tried to write a NNN for the Dataset from Quickdraw, but even after countless hours of reaserching I still get this error: TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.
More detail here: https://stackoverflow.com/questions/74962055/typeerror-cant-convert-np-ndarray-of-type-numpy-object
It is difficult to answer properly since you do not show us how you try to do it. From your error message I can see that you try to convert a numpy array containing objects to a torch tensor. This does not work, you will need a numeric data type:
import torch
import numpy as np
# Your test array without 'dtype=object'
a = np.array([
np.array([0.5, 1.0, 2.0], dtype=np.float16),
np.array([4.0, 6.0, 8.0], dtype=np.float16),
])
b = torch.from_numpy(a)
print(a.dtype) # This should not be 'object'
print(b)
Output
float16
tensor([[0.5000, 1.0000, 2.0000],
[4.0000, 6.0000, 8.0000]], dtype=torch.float16)
Just adding to what was written above:
First you should make sure your array dtype isn't a 'O' (Object).
You do that by: (credit)
a=np.vstack(a).astype(np.float)
Then you can use:
b = torch.from_numpy(a)
Looking at your error there might be some column in which already some numpy arrays are present.
Use this code, it will load without crashing you can debug further:
df = pd.read_csv("xxxxxx.csv", dtype=object)
Check your csv first and verify below link, lt is not a numpy error it is some issue with csv loading
https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html
I found the root cause. It is certainly numpy version issue. After I installed faiss using the pip install conda install -c pytorch faiss-cpu , the numpy version is overwritten to 1.26.4. Uninstall numpy and install again to get numpy 2.2.5 and use conda install faiss-cpu to install faiss, all issues are resolved.