[PaddlePaddle/PaddleOCR]做文本行识别时,我的文本行都是竖版的,但配置文件中transforms中默认48320,这样训练没有训练信息,但是改变成32048后就报错了,无法训练

2024-05-14 425 views
4

Train: transforms:

  • DecodeImage: img_mode: BGR channel_first: false
  • RecConAug: prob: 0.5 ext_data_num: 2 image_shape: [48, 320, 3] max_text_length: *max_text_length
  • RecAug:
  • MultiLabelEncode:
  • RecResizeImg: image_shape: [3, 48, 320]

报错信息: Traceback (most recent call last): File "tools/train.py", line 191, in main(config, device, logger, vdl_writer) File "tools/train.py", line 164, in main program.train(config, train_dataloader, valid_dataloader, device, model, File "/public/home/clhou/code/ocr_test/design_2.5/tools/program.py", line 285, in train preds = model(images, data=batch[1:]) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 930, in call return self._dygraph_call_func(*inputs, kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func outputs = self.forward(*inputs, *kwargs) File "/public/home/clhou/code/ocr_test/design_2.5/ppocr/modeling/architectures/base_model.py", line 85, in forward x = self.head(x, targets=data) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 930, in call return self._dygraph_call_func(inputs, kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func outputs = self.forward(*inputs, kwargs) File "/public/home/clhou/code/ocr_test/design_2.5/ppocr/modeling/heads/rec_multi_head.py", line 60, in forward ctc_encoder = self.ctc_encoder(x) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 930, in call return self._dygraph_call_func(*inputs, *kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func outputs = self.forward(inputs, kwargs) File "/public/home/clhou/code/ocr_test/design_2.5/ppocr/modeling/necks/rnn.py", line 190, in forward x = self.encoder_reshape(x) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 930, in call return self._dygraph_call_func(*inputs, *kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func outputs = self.forward(inputs, **kwargs) File "/public/home/clhou/code/ocr_test/design_2.5/ppocr/modeling/necks/rnn.py", line 33, in forward assert H == 1 AssertionError

回答

8

想问下,训练时对resize的尺寸有什么限制吗

4

Traceback (most recent call last): File "tools/train.py", line 192, in main(config, device, logger, vdl_writer) File "tools/train.py", line 165, in main program.train(config, train_dataloader, valid_dataloader, device, model, File "/public/home/clhou/code/ocr_test/paddleocr+ASF/tools/program.py", line 296, in train optimizer.step() File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), kw) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/base.py", line 299, in impl return func(*args, *kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, (extras + args), kw) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in impl return wrapped_func(*args, *kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/framework.py", line 434, in impl return func(args, **kwargs) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/optimizer/adam.py", line 450, in step optimize_ops = self._apply_optimize( File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/optimizer/optimizer.py", line 963, in _apply_optimize optimize_ops = self._create_optimization_pass(params_grads) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/optimizer/optimizer.py", line 749, in _create_optimization_pass self._create_accumulators(target_block, [ File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/optimizer/adam.py", line 317, in _create_accumulators self._add_moments_pows(p) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/optimizer/adam.py", line 283, in _add_moments_pows self._add_accumulator(self._moment2_acc_str, p, dtype=acc_dtype) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/optimizer/optimizer.py", line 615, in _add_accumulator self.helper.set_variable_initializer( File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/layer_helper_base.py", line 453, in set_variable_initializer initializer(var, self.main_program.global_block()) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/paddle/fluid/initializer.py", line 141, in call _C_ops.fill_constant(var, 'value', OSError: (External) CUDA error(700), an illegal memory access was encountered. [Hint: 'cudaErrorIllegalAddress'. The device encountered a load or store instruction on an invalid memory address. This leaves the process in an inconsistentstate and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. ] (at /paddle/paddle/fluid/platform/device/gpu/gpu_info.cc:124) [operator < fill_constant > error]

0

不要修改,默认48*320就行

训练的时候文字是横着的也能识别

1

不要修改,默认48*320就行

训练的时候文字是横着的也能识别

我不做修改的时候可以跑通(我的文本行是竖向的),但是loss基本不下降,而且infer也没有效果,于是我debug看了进入model前的image,发现横向的图片中只有一个字

1

imgtrain103 这是一个样例,差不多都这样

4

竖向的文字图像是什么样的,发个样例看下

0

竖向的文字图像是什么样的,发个样例看下

GL_807_2_10_48 我要做的就是这类文本行的识别,但是现在在这里出现了问题,希望可以得到指导,多谢

7

你把竖排的图像横过来(逆时针旋转90度),训练识别模型,也能识别到文字

3

你可以自己简单处理下,如果图像的宽度和高度比例小于一定的值,你把他旋转90度

9

你可以自己简单处理下,如果图像的宽度和高度比例小于一定的值,你把他旋转90度

您好,旋转这里我处理好来了,image进入model前我也保存看了没有问题了,不过去训练还是loss下降不下来,可能哪里有问题呢 [2023/02/28 12:57:52] ppocr INFO: epoch: [2/500], global_step: 910, lr: 0.000024, acc: 0.000000, norm_edit_dis: 0.006106, CTCLoss: 310.818420, SARLoss: 6.406378, loss: 317.229919, avg_reader_cost: 1.23864 s, avg_batch_cost: 1.61198 s, avg_samples: 89.6, ips: 55.58383 samples/s, eta: 9 days, 4:07:53 [2023/02/28 12:58:10] ppocr INFO: epoch: [2/500], global_step: 920, lr: 0.000024, acc: 0.000000, norm_edit_dis: 0.006677, CTCLoss: 310.127808, SARLoss: 6.398527, loss: 316.480713, avg_reader_cost: 1.22738 s, avg_batch_cost: 1.75810 s, avg_samples: 128.0, ips: 72.80597 samples/s, eta: 9 days, 4:07:32 [2023/02/28 12:58:23] ppocr INFO: epoch: [2/500], global_step: 930, lr: 0.000024, acc: 0.000000, norm_edit_dis: 0.006760, CTCLoss: 309.878357, SARLoss: 6.355027, loss: 316.247803, avg_reader_cost: 0.76346 s, avg_batch_cost: 1.29833 s, avg_samples: 128.0, ips: 98.58792 samples/s, eta: 9 days, 3:30:04 [2023/02/28 12:58:39] ppocr INFO: epoch: [2/500], global_step: 940, lr: 0.000025, acc: 0.000000, norm_edit_dis: 0.007354, CTCLoss: 309.566650, SARLoss: 6.409731, loss: 315.923218, avg_reader_cost: 1.11827 s, avg_batch_cost: 1.64835 s, avg_samples: 128.0, ips: 77.65359 samples/s, eta: 9 days, 3:21:21 [2023/02/28 12:58:53] ppocr INFO: epoch: [2/500], global_step: 950, lr: 0.000025, acc: 0.000000, norm_edit_dis: 0.007354, CTCLoss: 309.032684, SARLoss: 6.436466, loss: 315.395203, avg_reader_cost: 0.85524 s, avg_batch_cost: 1.39636 s, avg_samples: 128.0, ips: 91.66659 samples/s, eta: 9 days, 2:52:54 [2023/02/28 12:59:11] ppocr INFO: epoch: [2/500], global_step: 960, lr: 0.000025, acc: 0.000000, norm_edit_dis: 0.008305, CTCLoss: 308.398438, SARLoss: 6.423302, loss: 314.814636, avg_reader_cost: 1.25692 s, avg_batch_cost: 1.80362 s, avg_samples: 128.0, ips: 70.96822 samples/s, eta: 9 days, 2:56:53 [2023/02/28 12:59:24] ppocr INFO: epoch: [2/500], global_step: 970, lr: 0.000026, acc: 0.000000, norm_edit_dis: 0.007685, CTCLoss: 308.028992, SARLoss: 6.413594, loss: 314.516693, avg_reader_cost: 0.77235 s, avg_batch_cost: 1.30499 s, avg_samples: 128.0, ips: 98.08515 samples/s, eta: 9 days, 2:22:11 [2023/02/28 12:59:40] ppocr INFO: epoch: [2/500], global_step: 980, lr: 0.000026, acc: 0.000000, norm_edit_dis: 0.007668, CTCLoss: 307.679962, SARLoss: 6.401844, loss: 314.137085, avg_reader_cost: 1.03495 s, avg_batch_cost: 1.56928 s, avg_samples: 128.0, ips: 81.56628 samples/s, eta: 9 days, 2:08:26 [2023/02/28 12:59:52] ppocr INFO: epoch: [2/500], global_step: 990, lr: 0.000026, acc: 0.000000, norm_edit_dis: 0.007941, CTCLoss: 307.368652, SARLoss: 6.403132, loss: 313.789062, avg_reader_cost: 0.68935 s, avg_batch_cost: 1.22651 s, avg_samples: 128.0, ips: 104.36130 samples/s, eta: 9 days, 1:28:58 [2023/02/28 13:00:08] ppocr INFO: epoch: [2/500], global_step: 1000, lr: 0.000026, acc: 0.000000, norm_edit_dis: 0.007668, CTCLoss: 307.066040, SARLoss: 6.410324, loss: 313.484863, avg_reader_cost: 1.01300 s, avg_batch_cost: 1.55668 s, avg_samples: 128.0, ips: 82.22635 samples/s, eta: 9 days, 1:15:04 eval model:: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 16/16 [00:14<00:00, 1.11it/s] [2023/02/28 13:00:22] ppocr INFO: cur metric, acc: 0.0, norm_edit_dis: 0.003059896835559517, fps: 2990.5085888047397 [2023/02/28 13:00:23] ppocr INFO: save best model is to /public/home/clhou/code/ocroutput/REC/SVRT/best_accuracy [2023/02/28 13:00:23] ppocr INFO: best metric, acc: 0.0, norm_edit_dis: 0.003059896835559517, fps: 2990.5085888047397, best_epoch: 2 [2023/02/28 13:00:30] ppocr INFO: epoch: [2/500], global_step: 1010, lr: 0.000027, acc: 0.000000, norm_edit_dis: 0.008892, CTCLoss: 306.213898, SARLoss: 6.439404, loss: 312.625793, avg_reader_cost: 0.14822 s, avg_batch_cost: 0.67685 s, avg_samples: 128.0, ips: 189.11214 samples/s, eta: 8 days, 23:56:02 [2023/02/28 13:00:33] ppocr ERROR: When parsing line data_tps/comp/img_textline/image_934_204.jpg 槲𫣑 , error happened with msg: Traceback (most recent call last): File "/public/home/clhou/code/ocr_test/design_2.5/ppocr/data/simple_dataset.py", line 170, in getitem data['ext_data'] = self.get_ext_data() File "/public/home/clhou/code/ocr_test/design_2.5/ppocr/data/simple_dataset.py", line 117, in get_ext_data ii = Image.open(f) File "/public/home/clhou/anaconda3/envs/paddle/lib/python3.8/site-packages/PIL/Image.py", line 3023, in open raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file <_io.BufferedReader name='/public/home/clhou/code/ancient_data/rec_data/rec_real/data_tps/MTH1200/img_textline/QL_7_264_29.jpg'>

[2023/02/28 13:00:45] ppocr INFO: epoch: [2/500], global_step: 1020, lr: 0.000027, acc: 0.000000, norm_edit_dis: 0.008723, CTCLoss: 305.908875, SARLoss: 6.395550, loss: 312.390076, avg_reader_cost: 0.97319 s, avg_batch_cost: 1.49989 s, avg_samples: 128.0, ips: 85.33952 samples/s, eta: 8 days, 23:39:08

3

训练前期在warmup,loss下降比较慢,训练时间长了后效果有没有变好

3

老弟,你要指定预训练模型,效果就很快变好了