Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INT32 Failed on paddle.metric.accuracy #42845

Closed
mingxu1067 opened this issue May 18, 2022 · 4 comments
Closed

INT32 Failed on paddle.metric.accuracy #42845

mingxu1067 opened this issue May 18, 2022 · 4 comments
Assignees
Labels

Comments

@mingxu1067
Copy link
Collaborator

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

@paddle-bot-old
Copy link

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@wangxinxin08
Copy link
Contributor

目前该API只支持INT64的输入,感谢您的反馈,我们评估下是否需要支持INT32的输入

@mingxu1067
Copy link
Collaborator Author

那官方的文件可以考慮先移除INT32的相關訊息,這樣使用者比較不易混淆

label (Tensor)-数据类型为int64,int32。输入为数据集的标签。shape为 [sample_number, 1] 。

@wangxinxin08
Copy link
Contributor

wangxinxin08 commented May 19, 2022

收到,感谢反馈

onecatcn added a commit to onecatcn/docs that referenced this issue May 19, 2022
the doc was editted based on the discussion in the issue: 
INT32 Failed on paddle.metric.accuracy #42845
PaddlePaddle/Paddle#42845
onecatcn added a commit to onecatcn/Paddle that referenced this issue May 19, 2022
the doc was editted based on the discussion in the issue:
INT32 Failed on paddle.metric.accuracy: PaddlePaddle#42845
@Ligoml Ligoml added status/developed 开发完成 type/docs 文档问题 and removed status/new-issue 新建 type/bug-report 报bug labels May 20, 2022
TCChenlong pushed a commit to PaddlePaddle/docs that referenced this issue May 23, 2022
the doc was editted based on the discussion in the issue: 
INT32 Failed on paddle.metric.accuracy #42845
PaddlePaddle/Paddle#42845
jzhang533 pushed a commit that referenced this issue May 23, 2022
the doc was editted based on the discussion in the issue:
INT32 Failed on paddle.metric.accuracy: #42845
onecatcn added a commit to onecatcn/docs that referenced this issue May 25, 2022
the doc was editted based on the discussion in the issue:
INT32 Failed on paddle.metric.accuracy #42845
PaddlePaddle/Paddle#42845
onecatcn added a commit to onecatcn/Paddle that referenced this issue May 25, 2022
PR types
Bug fixes

PR changes
Docs

Describe
修复 paddle.metric.accuracy 文档,对应的中文文档修复为 PaddlePaddle/docs#4811
the file was editted based on the discussion in the issue:
INT32 Failed on paddle.metric.accuracy: PaddlePaddle#42845
TCChenlong pushed a commit to PaddlePaddle/docs that referenced this issue May 25, 2022
the doc was editted based on the discussion in the issue:
INT32 Failed on paddle.metric.accuracy #42845
PaddlePaddle/Paddle#42845
TCChenlong pushed a commit that referenced this issue May 25, 2022
PR types
Bug fixes

PR changes
Docs

Describe
修复 paddle.metric.accuracy 文档,对应的中文文档修复为 PaddlePaddle/docs#4811
the file was editted based on the discussion in the issue:
INT32 Failed on paddle.metric.accuracy: #42845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants