RuntimeError: Could not infer dtype of numpy.float32 problem solved

Recently, I encountered this problem when running a deep learning model, training the model, and testing the model. Finally, I found that the problem lies in the processing of the data.

pytorch version: 1.7.1

# 报错代码
label = label.astype("float32")
image = image.astype("float32")

After checking many blogs, I found this article: RUNTIMEERROR: COULD NOT INFER DTYPE OF COMPLEX (PYTORCH does not support plural data types yet), which refers to the data types in the official pytorch documentation .

insert image description here

The 32-bit float type can be represented by torch.float32 or torch.float, so the code was changed to the following:

# 修改代码
label = label.astype("float")
image = image.astype("float")

Found that the model can be successfully trained!

Guess you like

Origin blog.csdn.net/Alexa_/article/details/132687507