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

AttributeError: 'OCRPipeline' object has no attribute 'update_model_name' #1821

Open
350050183 opened this issue Jul 18, 2024 · 20 comments
Open
Assignees

Comments

@350050183
Copy link

官方demo
paddlex --pipeline OCR --model PP-OCRv4_mobile_det PP-OCRv4_mobile_rec --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png --device cpu

报错:

AttributeError: 'OCRPipeline' object has no attribute 'update_model_name'

检查了base/pipeline.py,发现仍有这个方法,但是OCRPipeline里却没有了?

PaddlePaddle 3.0.0-beta1
macOS M2

@cuicheng01
Copy link
Collaborator

您好,该问题已经修复,麻烦重新测试下呢?

@350050183
Copy link
Author

您好,该问题已经修复,麻烦重新测试下呢?

gitee不会同步更新?

@350050183
Copy link
Author

350050183 commented Jul 19, 2024

@TingquanGao @cuicheng01

请问一下使用PaddleX的PaddleOCR功能,执行文本检测可以返回正确的结果,但是文本识别就报错,是什么原因呢?

文本检测 代码
python main.py -c paddlex/configs/text_detection/PP-OCRv4_server_det.yaml -o Global.mode=predict -o Predict.model_dir="./output2/best_accuracy" -o Predict.input_path=1.png

会打印tensor系列出来。

文本识别 代码
python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml -o Global.mode=predict -o Predict.model_dir="./output2/best_accuracy" -o Predict.input_path=1.png

会返回错误

assert post_process_cfg['name'] == 'CTCLabelDecode'

Traceback (most recent call last):
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/utils/result_saver.py", line 30, in wrap
result = func(self, *args, **kwargs)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/engine.py", line 49, in run
predictor = build_predictor(self.config)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/predictor.py", line 189, in build_predictor
return PredictorBuilderByConfig(*args, **kwargs)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/predictor.py", line 173, in init
self.predictor = BasePredictor.get(model_name)(
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/utils/node.py", line 43, in _wrapper
ret = init_func(self, *args, **kwargs)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/predictor.py", line 56, in init
self.pre_tfs, self.post_tfs = self.build_transforms(pre_transforms,
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/predictor.py", line 70, in build_transforms
post_tfs = post_transforms if post_transforms is not None else self._get_post_transforms_from_config(
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/text_recognition/predictor/predictor.py", line 79, in _get_post_transforms_from_config
T.CTCLabelDecode(self.other_src.PostProcess), T.PrintResult()
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/utils/node.py", line 43, in _wrapper
ret = init_func(self, *args, **kwargs)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/text_recognition/predictor/transforms.py", line 187, in init
assert post_process_cfg['name'] == 'CTCLabelDecode'
AssertionError

如果使用以下命令

python main.py -c paddlex/configs/text_recognition/PP-OCRv4_server_rec.yaml -o Global.mode=predict -o Predict.model_dir="./output2/best_accuracy" -o Predict.input_path=1.png -o Predict.post_transforms=CTCLabelDecode -o Global.device=cpu

又会报错

A new field (post_transforms) detected!
Traceback (most recent call last):
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/utils/result_saver.py", line 30, in wrap
result = func(self, *args, **kwargs)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/engine.py", line 50, in run
return predictor.predict()
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/predictor.py", line 183, in predict
self.predictor.predict({'input_path': self.input_path})
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/predictor.py", line 93, in predict
mini_batch = self._run(batch_input=mini_batch)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/text_recognition/predictor/predictor.py", line 59, in _run
outputs = self.predictor.predict([input])
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/modules/base/predictor/utils/paddle_inference_predictor.py", line 138, in predict
self.predictor.run()
ValueError: (InvalidArgument) Broadcast dimension mismatch. Operands could not be broadcast together with the shape of X = [1, 256, 3, 20] and the shape of Y = [1, 256, 4, 20]. Received [3] in X is not equal to [4] in Y at i:2.
[Hint: Expected x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1 == true, but received x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1:0 != true:1.] (at /Users/paddle/xly/workspace/1622fd51-38d0-4d14-8168-9796039928d6/Paddle/paddle/phi/kernels/funcs/common_shape.h:84)
[operator < elementwise_add > error]

  • 报错里的 /Users/paddle/xly/ 是

@TingquanGao
Copy link
Collaborator

这个目录的模型./output2/best_accuracy是检测模型还是识别模型?是使用什么命令训练得到的呢?

@350050183
Copy link
Author

350050183 commented Jul 22, 2024

这个目录的模型./output2/best_accuracy是检测模型还是识别模型?是使用什么命令训练得到的呢?

python main.py -c ./train.yaml -o Global.mode=train -o Global.device=cpu -o Global.dataset_dir=./dataset_dir/

train.yaml的主要内容

Global:
model: PP-OCRv4_mobile_det
mode: check_dataset # check_dataset/train/evaluate/predict
module: text_det
dataset_dir: "/paddle/dataset/paddlex/ocr_det/ocr_det_dataset_examples"
device: cpu:0,1,2,3
output: "output"
CheckDataset:
convert:
enable: False
src_dataset_type: null
split:
enable: False
train_percent: null
val_percent: null
Train:
epochs_iters: 100
batch_size: 8
learning_rate: 0.001
pretrain_weight_path: null

@TingquanGao
Copy link
Collaborator

通过训练使用的配置文件可以看出来,模型./output2/best_accuracy是检测模型,所以使用该模型文件执行文本识别肯定会报错的。

@350050183
Copy link
Author

通过训练使用的配置文件可以看出来,模型./output2/best_accuracy是检测模型,所以使用该模型文件执行文本识别肯定会报错的。

我指令有覆盖配置文件里的。

@TingquanGao
Copy link
Collaborator

什么意思?

@350050183
Copy link
Author

什么意思?

python main.py -c ./train.yaml -o Global.mode=train -o Global.device=cpu -o Global.dataset_dir=./dataset_dir/

这里有指令是train,不是check_dataset

@TingquanGao
Copy link
Collaborator

train没问题,但训练的是检测模型啊:PP-OCRv4_mobile_det,所以训练产出的模型文件./output2/best_accuracy也是检测模型的相关文件,这些文件是无法用于执行识别的。

@350050183
Copy link
Author

我换成 PP-OCRv4_mobile_rec试下

@TingquanGao
Copy link
Collaborator

建议直接使用paddlex/configs/text_recognition/PP-OCRv4_mobile_rec.yaml这个配置文件来做训练和推理。

@350050183
Copy link
Author

好的,谢谢

@350050183
Copy link
Author

@TingquanGao

python main.py -c paddlex/configs/text_recognition/PP-OCRv4_mobile_rec.yaml -o Global.mode=train -o Global.device=cpu -o Train.epochs_iters=10 -o Global.dataset_dir=./dataset_dir/

环境

apple mini m2
pythone3.9
pip freeze|grep paddle
paddle2onnx==1.0.9
paddleclas @ file:///Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleClas
paddledet @ file:///Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleDetection
paddlefsl==1.1.0
paddlenlp @ file:///Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleNLP
paddleocr==2.8.1
paddlepaddle==3.0.0b1
paddleseg @ file:///Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleSeg
paddlets @ file:///Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleTS
-e git+https://github.com/PaddlePaddle/PaddleX.git@26666082d165514c1388f7909d99112792846b05#egg=paddlex

报错

I0722 13:51:08.804592 4032089088 kernel_dispatch.h:102] Get BackendSet from tensor
I0722 13:51:08.804601 4032089088 kernel_dispatch.h:102] Get BackendSet from tensor
[2024/07/22 13:51:08] ppocr INFO: train dataloader has 30 iters
[2024/07/22 13:51:08] ppocr INFO: valid dataloader has 10 iters
download https://paddleocr.bj.bcebos.com/pretrained/ch_PP-OCRv4_rec_trained.pdparams to /Users/bill/.paddleocr/models/ch_PP-OCRv4_rec_trained.pdparams
100%|██████████| 92.1M/92.1M [00:01<00:00, 50.1MiB/s]
[2024/07/22 13:51:11] ppocr WARNING: The shape of model params head.ctc_head.fc.weight [120, 1035] not matched with loaded params head.ctc_head.fc.weight [120, 6625] !
[2024/07/22 13:51:11] ppocr WARNING: The shape of model params head.ctc_head.fc.bias [1035] not matched with loaded params head.ctc_head.fc.bias [6625] !
[2024/07/22 13:51:11] ppocr WARNING: The shape of model params head.gtc_head.embedding.embedding.weight [1039, 384] not matched with loaded params head.gtc_head.embedding.embedding.weight [6629, 384] !
[2024/07/22 13:51:11] ppocr WARNING: The shape of model params head.gtc_head.tgt_word_prj.weight [384, 1039] not matched with loaded params head.gtc_head.tgt_word_prj.weight [384, 6629] !
[2024/07/22 13:51:11] ppocr INFO: load pretrain successful from /Users/bill/.paddleocr/models/ch_PP-OCRv4_rec_trained
[2024/07/22 13:51:11] ppocr INFO: During the training process, after the 0th iteration, an evaluation is run every 30 iterations
Exception in thread Thread-3:
Traceback (most recent call last):
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/simple_dataset.py", line 247, in getitem
outs = transform(data, self.ops[:-1])
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/imaug/init.py", line 56, in transform
data = op(data)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/imaug/rec_img_aug.py", line 53, in call
data = self.bda(data)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/imaug/rec_img_aug.py", line 93, in call
img = add_gasuss_noise(img)
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/imaug/rec_img_aug.py", line 726, in add_gasuss_noise
out = np.clip(out, 0, 255)
File "<array_function internals>", line 180, in clip
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 2154, in clip
return _wrapfunc(a, 'clip', a_min, a_max, out=out, **kwargs)
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return bound(*args, **kwds)
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/numpy/core/_methods.py", line 135, in _clip
if _clip_dep_is_scalar_nan(min):
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/numpy/core/_methods.py", line 95, in _clip_dep_is_scalar_nan
if ndim(a) != 0:
File "<array_function internals>", line 180, in ndim
RecursionError: maximum recursion depth exceeded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/paddle/io/dataloader/dataloader_iter.py", line 242, in _thread_loop
batch = self._dataset_fetcher.fetch(
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/paddle/io/dataloader/fetcher.py", line 77, in fetch
data.append(self.dataset[idx])
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/simple_dataset.py", line 259, in getitem
return self.getitem([img_width, img_height, rnd_idx, wh_ratio])
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/simple_dataset.py", line 259, in getitem
return self.getitem([img_width, img_height, rnd_idx, wh_ratio])
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/simple_dataset.py", line 259, in getitem
return self.getitem([img_width, img_height, rnd_idx, wh_ratio])
[Previous line repeated 976 more times]
File "/Users/bill/Downloads/paddlex-3.0/PaddleX/paddlex/repo_manager/repos/PaddleOCR/ppocr/data/simple_dataset.py", line 254, in getitem
data_line, traceback.format_exc()))
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/traceback.py", line 167, in format_exc
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/traceback.py", line 120, in format_exception
return list(TracebackException(
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/exceptiongroup/_formatting.py", line 248, in format
yield from _ctx.emit(exc.format_exception_only())
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/exceptiongroup/_formatting.py", line 64, in emit
for text in text_gen:
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/site-packages/exceptiongroup/_formatting.py", line 335, in format_exception_only
if isinstance(self.notes, collections.abc.Sequence):
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/abc.py", line 119, in instancecheck
return _abc_instancecheck(cls, instance)
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/abc.py", line 123, in subclasscheck
return _abc_subclasscheck(cls, subclass)
File "/Users/bill/anaconda3/envs/paddlex/lib/python3.9/abc.py", line 123, in subclasscheck
return _abc_subclasscheck(cls, subclass)
RecursionError: maximum recursion depth exceeded

@350050183
Copy link
Author

卡死了在上面的错误里

@cuicheng01
Copy link
Collaborator

我看你使用的是cpu训练,非常不建议哈,因为这些模型至少也都需要单卡gpu来训练

@350050183
Copy link
Author

我看你使用的是cpu训练,非常不建议哈,因为这些模型至少也都需要单卡gpu来训练

但是paddlepaddle不支持mac的GPU

Currently, only the CPU version of PaddlePaddle is supported in the macOS environment

https://www.paddlepaddle.org.cn/documentation/docs/en/install/pip/macos-pip_en.html

@cuicheng01
Copy link
Collaborator

嗯嗯,这里特指NV的GPU

@350050183
Copy link
Author

嗯嗯,这里特指NV的GPU

paddleX的paddleOCR套件也不支持paddle2.6.1,非得要安装paddle3.0,paddle3.0又不支持macOS
各种不兼容。
难道只能使用NV GPU才能玩了?

@350050183
Copy link
Author

tensorflow 在 macos 安装以下组件是能支持GPU的
pip install tensorflow-macos tensorflow-metal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants