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

ValueError when use det only / 单独执行检测时报错 ValueError #11761

Closed
KumaTea opened this issue Mar 18, 2024 · 8 comments
Closed

ValueError when use det only / 单独执行检测时报错 ValueError #11761

KumaTea opened this issue Mar 18, 2024 · 8 comments
Assignees
Labels
detection status/close triaged this issue has been looked, and triaged.

Comments

@KumaTea
Copy link

KumaTea commented Mar 18, 2024

问题

使用 PaddleOCR 单独执行检测时,报错 ValueError

import numpy as np
from paddleocr import PaddleOCR


ppocr = PaddleOCR(lang='ch', use_angle_cls=False,)

image: np.ndarray = ...
results = ppocr.ocr(image, det=True, rec=False, cls=False)
print(results)

报错如下:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\ProgramData\conda\envs\gsds\Lib\site-packages\paddleocr\paddleocr.py", line 674, in ocr
    if not dt_boxes:
           ^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

出错位置

paddleocr.py#L681

其中,dt_boxes 数据示例

dt_boxes = np.array([[
    [ 515.,    4.],
    [1127.,    4.],
    [1127.,   41.],
    [ 515.,   41.]
]], dtype=np.float32)

print(f'{dt_boxes.all()=}')
print(f'{dt_boxes.any()=}')
dt_boxes.all()=True
dt_boxes.any()=True

临时解决方案

if not dt_boxes: 改为 if not dt_boxes.all():

更正:dt_boxes 为 None 时会报错

if not dt_boxes: 改为 if dt_boxes is None or not dt_boxes.all():


  • 系统环境/System Environment:Windows 11 x64 23H2 / Python 3.12.2
  • 版本号/Version:Paddle:v2.6.0 PaddleOCR:v2.7.0.3 问题相关组件/Related components:paddleocr.PaddleOCR.ocr
  • 运行指令/Command Code:ocr.ocr(image, det=True, rec=False, cls=False)
  • 完整报错/Complete Error Message:ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
@GreatV
Copy link
Collaborator

GreatV commented Mar 19, 2024

dygraph 分支好像也是有类似的问题

paddleocr --image_dir ./doc/imgs/11.jpg --use_angle_cls False --use_gpu false --det True --rec False
[2024/03/19 10:23:16] ppocr INFO: **********./doc/imgs/11.jpg**********
[2024/03/19 10:23:16] ppocr INFO: [[27.0, 458.0], [137.0, 458.0], [137.0, 479.0], [27.0, 479.0]]
Traceback (most recent call last):
  File "/Users/wangxin/miniconda3/envs/ppocr-dev/bin/paddleocr", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/wangxin/miniconda3/envs/ppocr-dev/lib/python3.11/site-packages/paddleocr/paddleocr.py", line 825, in main
    val += str(box[0]) + ',' + str(box[1]) + ','
               ~~~^^^
TypeError: 'float' object is not subscriptable
(ppocr-dev) 

@GreatV
Copy link
Collaborator

GreatV commented Mar 19, 2024

@KumaTea 你可以提一个PR,修复这个问题。

@KumaTea
Copy link
Author

KumaTea commented Mar 23, 2024

该问题数月前已在 commit 42d2809 修复,只是没有同步到主分支,故关闭

@KumaTea KumaTea closed this as completed Mar 23, 2024
@KumaTea KumaTea reopened this Apr 1, 2024
@KumaTea
Copy link
Author

KumaTea commented Apr 1, 2024

Reopen as the fix still not merged in the latest version (v2.7.3)...

@UserWangZz
Copy link
Collaborator

你好感谢提出问题,我们会记录并进行修复

@UserWangZz UserWangZz added triaged this issue has been looked, and triaged. detection labels Apr 30, 2024
@SWHL
Copy link
Collaborator

SWHL commented Jun 10, 2024

已经在PR #11287 中修复,且merged

@SWHL SWHL closed this as completed Jun 10, 2024
@alixunxing
Copy link

不仅仅是这一个判断的问题,det only里面bboxes整个是有问题的。真不知道为啥要写一个这么复杂的函数

@alixunxing
Copy link

已经把ppocr拆出来重写了

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
detection status/close triaged this issue has been looked, and triaged.
Projects
None yet
Development

No branches or pull requests

6 participants