[PaddlePaddle/PaddleOCR]PPOCRLabel开启时报错,打不开

2024-05-13 392 views
5

请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem

  • 系统环境/System Environment:python 3.11.4
  • 版本号/Version:Paddle: PaddleOCR: 问题相关组件/Related components:PPOCRLabel
  • 运行指令/Command Code:python.exe D:\Git\PaddleOCR\PPOCRLabel\PPOCRLabel.py
  • 完整报错/Complete Error Message: D:\User\Documents\PaddleOCR\Scripts\python.exe D:\Git\PaddleOCR\PPOCRLabel\PPOCRLabel.py [2023/08/26 00:11:49] ppocr WARNING: When args.layout is false, args.ocr is automatically set to false Traceback (most recent call last): File "D:\Git\PaddleOCR\PPOCRLabel\PPOCRLabel.py", line 2840, in sys.exit(main()) ^^^^^^ File "D:\Git\PaddleOCR\PPOCRLabel\PPOCRLabel.py", line 2828, in main app, _win = get_main_app(sys.argv) ^^^^^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\PPOCRLabel\PPOCRLabel.py", line 2818, in get_main_app win = MainWindow(lang=args.lang, ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\PPOCRLabel\PPOCRLabel.py", line 112, in init result = self.table_ocr('./data/paddle.png', return_ocr_result_intable=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\paddleocr.py", line 759, in call res, = super().call( ^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\ppstructure\predict_system.py", line 129, in call res, table_time_dict = self.table_system( ^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\ppstructure\table\predict_table.py", line 86, in call structure_res, elapse = self._structure(copy.deepcopy(img)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\ppstructure\table\predict_table.py", line 109, in _structure structure_res, elapse = self.table_structurer(copy.deepcopy(img)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\ppstructure\table\predict_structure.py", line 120, in call data = transform(data, self.preprocess_op) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Git\PaddleOCR\ppocr\data\imaug__init.py", line 56, in transform data = op(data) ^^^^^^^^ File "D:\Git\PaddleOCR\ppocr\data\imaug\operators.py", line 94, in call__ img.astype('float32') * self.scale - self.mean) / self.std
    
    ValueError: operands could not be broadcast together with shapes (213,488,4) (1,1,3) 
    我们提供了AceIssueSolver来帮助你解答问题,你是否想要它来解答(请填写yes/no)?/We provide AceIssueSolver to solve issues, do you want it? (Please write yes/no):

请尽量不要包含图片在问题中/Please try to not include the image in the issue.

回答

7

从报错上面看(213,488,4)应该是图像的透明通道也被读取了,请确认是否修改了部分代码?尤其是图像读取的部分,输入的图像矩阵需要是三通道的,目前在最先版本代码中尚不能复现该问题。

2

我这边也会报这个错。 python版本 3.11, 代码 是2.7 release。

5

@chenhao86 @CarlWangMing 抱歉,在python版本 3.11, 代码 是2.7 release,windows环境 已经复现该问题。 快速修复方法为,修改代码./paddleocr.py 中img_decode函数中515行的return cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED) 修改为 return cv2.imdecode(np_arr, cv2.IMREAD_COLOR)

原因如下: 如上文所说,是图像通道问题,由于示例图片是四通道图像,而imread参数使用IMREAD_UNCHANGED,导致透明通道被提取从而引发的通道数溢出问题(需要三通道图像,读取透明通道后变为四通道图像)

7

@Gmgge 专业啊。

3

感谢大佬

5

最新的2.7.0.3 的paddleocr.py 並沒有加入此修正,導致PPOCRLabel 啟動仍會有相同問題

6

@chenhao86 @CarlWangMing 抱歉,在python版本 3.11, 代码 是2.7 release,windows环境 已经复现该问题。 快速修复方法为,修改代码./paddleocr.py 中img_decode函数中515行的return cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED) 修改为 return cv2.imdecode(np_arr, cv2.IMREAD_COLOR)

原因如下: 如上文所说,是图像通道问题,由于示例图片是四通道图像,而imread参数使用IMREAD_UNCHANGED,导致透明通道被提取从而引发的通道数溢出问题(需要三通道图像,读取透明通道后变为四通道图像)

牛逼

2

@chenhao86 @CarlWangMing 抱歉,在python版本 3.11, 代码 是2.7 release,windows环境 已经复现该问题。 快速修复方法为,修改代码./paddleocr.py 中img_decode函数中515行的return cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED) 修改为 return cv2.imdecode(np_arr, cv2.IMREAD_COLOR)

原因如下: 如上文所说,是图像通道问题,由于示例图片是四通道图像,而imread参数使用IMREAD_UNCHANGED,导致透明通道被提取从而引发的通道数溢出问题(需要三通道图像,读取透明通道后变为四通道图像)

同样问题,正确解决。 注意:要修改的paddleocr.py文件在报错提示路径中找到【我的错误提示文件路径是**anaconda3\envs\orc\lib\site-packages\paddleocr\paddleocr.py】,我第一次修改的是git下来的文件夹中的,搞错了

1

关于“ValueError: operands could not be broadcast together with shapes (213,488,4) (1,1,3)”的问题 吃井不忘挖水人,在PPOCRLabel.py脚本里的112行,把result = self.table_ocr('./data/paddle.png', return_ocr_result_in_table=True)这一句注释掉就行了,软件可以正常打开使用

2

关于“ValueError: operands could not be broadcast together with shapes (213,488,4) (1,1,3)”的问题 吃井不忘挖水人,在PPOCRLabel.py脚本里的112行,把result = self.table_ocr('./data/paddle.png', return_ocr_result_in_table=True)这一句注释掉就行了,软件可以正常打开使用

通过这个方法解决了,非常感谢

2

关于“ValueError: operands could not be broadcast together with shapes (213,488,4) (1,1,3)”的问题 吃井不忘挖水人,在PPOCRLabel.py脚本里的112行,把result = self.table_ocr('./data/paddle.png', return_ocr_result_in_table=True)这一句注释掉就行了,软件可以正常打开使用

我也解决了,但是后面自动标注完,点击确认OK,又闪退了,报错日志是: Trying to construct an instance of an invalid type, type id: 1055783631 Traceback (most recent call last): File "PPOCRLabel.py", line 1060, in shapeSelectionChanged shape.selected = True AttributeError: 'NoneType' object has no attribute 'selected'

8

关于“ValueError: operands could not be broadcast together with shapes (213,488,4) (1,1,3)”的问题 吃井不忘挖水人,在PPOCRLabel.py脚本里的112行,把result = self.table_ocr('./data/paddle.png', return_ocr_result_in_table=True)这一句注释掉就行了,软件可以正常打开使用

这是正解 另一个没用

0

Labe

用了這個解決了 前一個做法沒反應!

7

2.7.1依然存在该问题吗?取消示例图片可以运行是因为示例图片是个四通道图像,之前的逻辑处理四通道图像会出现bug,如果不从根本原因上面解决,在标注时遇到四通道图像仍然可能会闪退。

4

方法一:

@chenhao86 @CarlWangMing 抱歉,在python版本 3.11, 代码 是2.7 release,windows环境 已经复现该问题。 快速修复方法为,修改代码./paddleocr.py 中img_decode函数中515行的return cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED) 修改为 return cv2.imdecode(np_arr, cv2.IMREAD_COLOR) 原因如下: 如上文所说,是图像通道问题,由于示例图片是四通道图像,而imread参数使用IMREAD_UNCHANGED,导致透明通道被提取从而引发的通道数溢出问题(需要三通道图像,读取透明通道后变为四通道图像)

同样问题,正确解决。 注意:要修改的paddleocr.py文件在报错提示路径中找到【我的错误提示文件路径是**anaconda3\envs\orc\lib\site-packages\paddleocr\paddleocr.py】,我第一次修改的是git下来的文件夹中的,搞错了

方法二:

关于“ValueError: operands could not be broadcast together with shapes (213,488,4) (1,1,3)”的问题 吃井不忘挖水人,在PPOCRLabel.py脚本里的112行,把result = self.table_ocr('./data/paddle.png', return_ocr_result_in_table=True)这一句注释掉就行了,软件可以正常打开使用

实测两者均有效

6

抱歉,在python版本 3.11, 代码 是2.7 release,windows环境 已经复现该问题。 快速修复方法为,修改代码./paddleocr.py 中img_decode函数中515行的return cv2.imdecode(np_arr, cv2.IMREAD_UNCHANGED) 修改为 return cv2.imdecode(np_arr, cv2.IMREAD_COLOR) 原因如下: 如上文所说,是图像通道问题,由于示例图片是四通道图像,而imread参数使用IMREAD_UNCHANGED,导致透明通道被提取从而引发的通道数溢出问题(需要三通道图像,读取透明通道后变为四通道图像) ------ 我使用的是這個方式不過是要修改PYTHON環境裡的PADDLEOCR.PY像我一樣的小白會誤以為是下載下來的OCR資料夾裡的