This is a known error, you need to uninstall numpy by:
pip uninstall numpy
then install "numpy<1.26.4" afresh.
pip install "numpy<1.26.4"
References:
https://github.com/huggingface/diffusers/issues/9069#issuecomment-2267596351
https://github.com/pytorch/pytorch/issues/135836#issuecomment-2347209235
Answer from Talha Tayyab on Stack OverflowThis is a known error, you need to uninstall numpy by:
pip uninstall numpy
then install "numpy<1.26.4" afresh.
pip install "numpy<1.26.4"
References:
https://github.com/huggingface/diffusers/issues/9069#issuecomment-2267596351
https://github.com/pytorch/pytorch/issues/135836#issuecomment-2347209235
After a number of trials I figure out why there is problem.
Note that there are two numpy versions numpy (1.26.4) and numpy-base (2.1.2) in the installation. If you uninstall numpy (1.26.4) and then reinstall by conda install numpy==1.26.0, your error will remain; what you need to do is to pip uninstall numpy again to ensure the version 2.1.2 is also removed.
np.ndArray in tensor - Beginner (2018)
Why do I get "TypeError: expected np.ndarray (got numpy.ndarray)" when I use torch.from_numpy() function?
python - expected np.ndarray (got DataFrame) - Stack Overflow
python - how to convert series numpy array into tensors using pytorch - Stack Overflow
Essentially, the numpy array can be converted into a Tensor using just from_numpy(), it is not required to use .type() again.
Example:
X = numpy.array([1, 2, 3])
X = torch.from_numpy(X)
print(X) # tensor([ 1, 2, 3])
Please check this Torch documentation page for detailed reference. https://pytorch.org/docs/stable/generated/torch.from_numpy.html
because you X and y not numpy array, you can use
X=torch.from_numpy(np.array(X)).type(torch.float)