paddle报ValueError: The type of data we are trying to retrieve does not match the type

错误原因

在使用paddlepaddle训练模型的时候,使用numpy随机生成一些数据来训练一个线程模型的时候报The type of data we are trying to retrieve does not match the type of data currently contained in the container

错误信息

	pre_bias = _C_ops.matmul_v2(x, weight, 'trans_x', False, 'trans_y',
ValueError: (InvalidArgument) The type of data we are trying to retrieve does not match the type of data currently contained in the container.
  [Hint: Expected dtype() == paddle::experimental::CppTypeToDataType<T>::Type(), but received dtype():12 != paddle::experimental::CppTypeToDataType<T>::Type():13.] (at /paddle/paddle/phi/core/dense_tensor.cc:137)
  [operator < matmul_v2 > error]

原因分析及解决办法

因为np.random.rand生成的数据默认是float64的数据类型,而paddlepaddle是不支持的,所以我们需要将其转换成为float32的数据类型,转换代码如下

np.random.rand(num_samples,2).astype("float32")

猜你喜欢

转载自blog.csdn.net/sinat_29957455/article/details/127353029