-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
Description
bug描述 Describe the Bug
paddle.metric.accuracy
fails when dtype
of label
is int32
, even documents said it is allowed to be.
Reproduce Python Script:
import paddle
predictions = paddle.to_tensor([[0.2, 0.1, 0.4, 0.1, 0.1], [0.2, 0.3, 0.1, 0.15, 0.25]], dtype='float32')
print("Run with Label INT64")
label_int64 = paddle.to_tensor([[2], [0]], dtype="int64")
result = paddle.metric.accuracy(input=predictions, label=label_int64, k=1)
print(result)
print("INT64 Test Done\n")
print("Run with Label INT32")
label_int32 = paddle.to_tensor([[2], [0]], dtype="int32")
result = paddle.metric.accuracy(input=predictions, label=label_int32, k=1)
print(result)
print("INT32 Test Done\n")
Error Message:
- v2.3.0
- Docker image: paddlepaddle/paddle:2.3.0
- log
Run with Label INT64
Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
[0.50000000])
INT64 Test Done
Run with Label INT32
Traceback (most recent call last):
File "test.py", line 13, in <module>
result = paddle.metric.accuracy(input=predictions, label=label_int32, k=1)
File "/usr/local/lib/python3.7/dist-packages/paddle/metric/metrics.py", line 802, in accuracy
total)
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():5 != paddle::experimental::CppTypeToDataType<T>::Type():7.] (at /paddle/paddle/phi/core/dense_tensor.cc:137)
[operator < accuracy > error]
- v2.2.2
- Docker image: paddlepaddle/paddle:2.2.2
- log
Run with Label INT64
Tensor(shape=[1], dtype=float32, place=CPUPlace, stop_gradient=True,
[0.50000000])
INT64 Test Done
Run with Label INT32
Traceback (most recent call last):
File "test.py", line 13, in <module>
result = paddle.metric.accuracy(input=predictions, label=label_int32, k=1)
File "/usr/local/lib/python3.7/dist-packages/paddle/metric/metrics.py", line 802, in accuracy
total)
ValueError: (InvalidArgument) Tensor holds the wrong type, it holds int, but desires to be int64_t.
[Hint: Expected valid == true, but received valid:0 != true:1.] (at /paddle/paddle/fluid/framework/tensor_impl.h:33)
[operator < accuracy > error]
其他补充信息 Additional Supplementary Information
No response