PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
43.46k stars 7.75k forks source link

训练方向检测模型 #5113

Closed zhaoweihan2017 closed 2 years ago

zhaoweihan2017 commented 2 years ago

训练方向检测模型:配置文件如下: Global: use_gpu: true epoch_num: 50 log_smooth_window: 20 print_batch_step: 50 save_model_dir: ./output/cls/mv3/ save_epoch_step: 200

evaluation is run every 5000 iterations after the 4000th iteration

eval_batch_step: [0, 500] cal_metric_during_train: True pretrained_model: ./pretrain_models/ch_ppocr_mobile_v2.0_cls_train/best_accuracy checkpoints: save_inference_dir: use_visualdl: False infer_img: doc/imgs_words_en/word_10.png label_list: ['0','90','180','270']

Architecture: model_type: cls algorithm: CLS Transform: Backbone: name: MobileNetV3 scale: 0.35 model_name: small Neck: Head: name: ClsHead class_dim: 2

Loss: name: ClsLoss

Optimizer: name: Adam beta1: 0.9 beta2: 0.999 lr: name: Cosine learning_rate: 0.0002 regularizer: name: 'L2' factor: 0

PostProcess: name: ClsPostProcess

Metric: name: ClsMetric main_indicator: acc

Train: dataset: name: SimpleDataSet data_dir: ./train_data/cls/ label_file_list:

Eval: dataset: name: SimpleDataSet data_dir: ./train_data/cls/ label_file_list:

配置label_list 支持90 与 270 启动训练报错如下: Traceback (most recent call last): File "tools/train.py", line 131, in main(config, device, logger, vdl_writer) File "tools/train.py", line 108, in main eval_class, pre_best_model_dict, logger, vdl_writer) File "/home/paddleopr/model_train/PaddleOCR-release-2.3/tools/program.py", line 222, in train loss = loss_class(preds, batch) File "/home/paddleopr/.local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 914, in call outputs = self.forward(*inputs, *kwargs) File "/home/paddleopr/model_train/PaddleOCR-release-2.3/ppocr/losses/cls_loss.py", line 29, in forward loss = self.loss_func(input=predicts, label=label) File "/home/paddleopr/.local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 914, in call outputs = self.forward(inputs, **kwargs) File "/home/paddleopr/.local/lib/python3.7/site-packages/paddle/nn/layer/loss.py", line 406, in forward name=self.name) File "/home/paddleopr/.local/lib/python3.7/site-packages/paddle/nn/functional/loss.py", line 1671, in cross_entropy format(invalid_label[0], input.shape[axis] - 1)) ValueError: Target(Tensor(shape=[1], dtype=int64, place=CUDAPlace(0), stop_gradient=True, [2])) is out of class_dimension's upper bound(1)

请问下如何解决?

ioracion commented 2 years ago

你的label_list有4个,而class_dim却是2

happybuby commented 2 years ago

你的label_list有4个,而class_dim却是2

这个应该调整哪里啊 @ioracion

ioracion commented 2 years ago

class_dim改成4就好了...

happybuby commented 2 years ago

class_dim改成4就好了...

已经可以正常训练了,谢谢 @ioracion

zhaoweihan2017 commented 2 years ago

class_dim改成4就好了...

赞,可以了,感谢啊。@ioracion

Thea228 commented 2 years ago

请问cls模型要怎么训练呢,标签要怎么打啊……

paddle-bot-old[bot] commented 2 years ago

Since you haven\'t replied for more than 3 months, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. It is recommended to pull and try the latest code first. 由于您超过三个月未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。