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
44.09k stars 7.81k forks source link

cls 训练始终acc = 1,训练完永远识别成同一个label #2939

Closed gavin2059 closed 3 years ago

gavin2059 commented 3 years ago

我想让cls能够识别4个角度。 第一个iteration acc就等于1,loss会在0.48开始,慢慢变少。。。 训练完了以后,什么都会识别成 第一个在label_list里在train.txt出现的label。 请问我是不是哪里没置好?谢谢!

train.txt: train/1d.jpg 180 train/1l.jpg 270 train/1r.jpg 90 train/1u.jpg 0 train/2d.jpg 180 train/2l.jpg 270 train/2r.jpg 90 train/2u.jpg 0 等等

Log: [2021/05/27 18:04:32] root INFO: Architecture : [2021/05/27 18:04:32] root INFO: Backbone : [2021/05/27 18:04:32] root INFO: model_name : small [2021/05/27 18:04:32] root INFO: name : MobileNetV3 [2021/05/27 18:04:32] root INFO: scale : 0.35 [2021/05/27 18:04:32] root INFO: Head : [2021/05/27 18:04:32] root INFO: class_dim : 2 [2021/05/27 18:04:32] root INFO: name : ClsHead [2021/05/27 18:04:32] root INFO: Neck : None [2021/05/27 18:04:32] root INFO: Transform : None [2021/05/27 18:04:32] root INFO: algorithm : CLS [2021/05/27 18:04:32] root INFO: model_type : cls [2021/05/27 18:04:32] root INFO: Eval : [2021/05/27 18:04:32] root INFO: dataset : [2021/05/27 18:04:32] root INFO: data_dir : ./train_data/cls [2021/05/27 18:04:32] root INFO: label_file_list : ['./train_data/cls/trainbac.txt'] [2021/05/27 18:04:32] root INFO: name : SimpleDataSet [2021/05/27 18:04:32] root INFO: transforms : [2021/05/27 18:04:32] root INFO: DecodeImage : [2021/05/27 18:04:32] root INFO: channel_first : False [2021/05/27 18:04:32] root INFO: img_mode : BGR [2021/05/27 18:04:32] root INFO: ClsLabelEncode : None [2021/05/27 18:04:32] root INFO: ClsResizeImg : [2021/05/27 18:04:32] root INFO: image_shape : [3, 48, 192] [2021/05/27 18:04:32] root INFO: KeepKeys : [2021/05/27 18:04:32] root INFO: keep_keys : ['image', 'label'] [2021/05/27 18:04:32] root INFO: loader : [2021/05/27 18:04:32] root INFO: batch_size_per_card : 15 [2021/05/27 18:04:32] root INFO: drop_last : False [2021/05/27 18:04:32] root INFO: num_workers : 4 [2021/05/27 18:04:32] root INFO: shuffle : False [2021/05/27 18:04:32] root INFO: Global : [2021/05/27 18:04:32] root INFO: cal_metric_during_train : True [2021/05/27 18:04:32] root INFO: checkpoints : None [2021/05/27 18:04:32] root INFO: debug : False [2021/05/27 18:04:32] root INFO: distributed : False [2021/05/27 18:04:32] root INFO: epoch_num : 100 [2021/05/27 18:04:32] root INFO: eval_batch_step : [0, 100] [2021/05/27 18:04:32] root INFO: infer_img : doc/imgs_words_en/word_10.png [2021/05/27 18:04:32] root INFO: label_list : ['0', '180', '90', '270'] [2021/05/27 18:04:32] root INFO: log_smooth_window : 20 [2021/05/27 18:04:32] root INFO: pretrained_model : None [2021/05/27 18:04:32] root INFO: print_batch_step : 10 [2021/05/27 18:04:32] root INFO: save_epoch_step : 5 [2021/05/27 18:04:32] root INFO: save_inference_dir : None [2021/05/27 18:04:32] root INFO: save_model_dir : ./output/cls/mv3/ [2021/05/27 18:04:32] root INFO: use_gpu : False [2021/05/27 18:04:32] root INFO: use_visualdl : False [2021/05/27 18:04:32] root INFO: Loss : [2021/05/27 18:04:32] root INFO: name : ClsLoss [2021/05/27 18:04:32] root INFO: Metric : [2021/05/27 18:04:32] root INFO: main_indicator : acc [2021/05/27 18:04:32] root INFO: name : ClsMetric [2021/05/27 18:04:32] root INFO: Optimizer : [2021/05/27 18:04:32] root INFO: beta1 : 0.9 [2021/05/27 18:04:32] root INFO: beta2 : 0.999 [2021/05/27 18:04:32] root INFO: lr : [2021/05/27 18:04:32] root INFO: learning_rate : 0.001 [2021/05/27 18:04:32] root INFO: name : Cosine [2021/05/27 18:04:32] root INFO: name : Adam [2021/05/27 18:04:32] root INFO: regularizer : [2021/05/27 18:04:32] root INFO: factor : 0 [2021/05/27 18:04:32] root INFO: name : L2 [2021/05/27 18:04:32] root INFO: PostProcess : [2021/05/27 18:04:32] root INFO: name : ClsPostProcess [2021/05/27 18:04:32] root INFO: Train : [2021/05/27 18:04:32] root INFO: dataset : [2021/05/27 18:04:32] root INFO: data_dir : ./train_data/cls [2021/05/27 18:04:32] root INFO: label_file_list : ['./train_data/cls/train.txt'] [2021/05/27 18:04:32] root INFO: name : SimpleDataSet [2021/05/27 18:04:32] root INFO: transforms : [2021/05/27 18:04:32] root INFO: DecodeImage : [2021/05/27 18:04:32] root INFO: channel_first : False [2021/05/27 18:04:32] root INFO: img_mode : BGR [2021/05/27 18:04:32] root INFO: ClsLabelEncode : None [2021/05/27 18:04:32] root INFO: RecAug : [2021/05/27 18:04:32] root INFO: use_tia : True [2021/05/27 18:04:32] root INFO: RandAugment : None [2021/05/27 18:04:32] root INFO: ClsResizeImg : [2021/05/27 18:04:32] root INFO: image_shape : [3, 48, 192] [2021/05/27 18:04:32] root INFO: KeepKeys : [2021/05/27 18:04:32] root INFO: keep_keys : ['image', 'label'] [2021/05/27 18:04:32] root INFO: loader : [2021/05/27 18:04:32] root INFO: batch_size_per_card : 15 [2021/05/27 18:04:32] root INFO: drop_last : True [2021/05/27 18:04:32] root INFO: num_workers : 8 [2021/05/27 18:04:32] root INFO: shuffle : True [2021/05/27 18:04:32] root INFO: train with paddle 2.0.0 and device CPUPlace [2021/05/27 18:04:32] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:04:32] root INFO: Initialize indexs of datasets:['./train_data/cls/trainbac.txt'] [2021/05/27 18:04:32] root INFO: train from scratch [2021/05/27 18:04:32] root INFO: train dataloader has 5 iters [2021/05/27 18:04:32] root INFO: valid dataloader has 0 iters [2021/05/27 18:04:32] root INFO: No Images in eval dataset, evaluation during training will be disabled [2021/05/27 18:04:32] root INFO: During the training process, after the 1e+111th iteration, an evaluation is run every 100 iterations [2021/05/27 18:04:33] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:05:27] root INFO: epoch: [1/100], iter: 4, lr: 0.001000, loss: 0.486486, acc: 1.000000, reader_cost: 5.30012 s, batch_cost: 5.43455 s, samples: 75, ips: 1.38006 [2021/05/27 18:05:27] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:05:27] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:06:07] root INFO: epoch: [2/100], iter: 9, lr: 0.001000, loss: 0.254765, acc: 1.000000, reader_cost: 3.87785 s, batch_cost: 3.99482 s, samples: 75, ips: 1.87743 [2021/05/27 18:06:07] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:06:07] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:06:30] root INFO: epoch: [3/100], iter: 10, lr: 0.001000, loss: 0.219832, acc: 1.000000, reader_cost: 2.26816 s, batch_cost: 2.29694 s, samples: 15, ips: 0.65304 [2021/05/27 18:06:45] root INFO: epoch: [3/100], iter: 14, lr: 0.001000, loss: 0.135695, acc: 1.000000, reader_cost: 1.41106 s, batch_cost: 1.50844 s, samples: 60, ips: 3.97761 [2021/05/27 18:06:45] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:06:45] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:07:22] root INFO: epoch: [4/100], iter: 19, lr: 0.000999, loss: 0.074743, acc: 1.000000, reader_cost: 3.53276 s, batch_cost: 3.65492 s, samples: 75, ips: 2.05203 [2021/05/27 18:07:22] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:07:22] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:07:56] root INFO: epoch: [5/100], iter: 20, lr: 0.000999, loss: 0.058561, acc: 1.000000, reader_cost: 3.38621 s, batch_cost: 3.41061 s, samples: 15, ips: 0.43980 [2021/05/27 18:07:57] root INFO: epoch: [5/100], iter: 24, lr: 0.000998, loss: 0.027465, acc: 1.000000, reader_cost: 0.00002 s, batch_cost: 0.09287 s, samples: 60, ips: 64.60553 [2021/05/27 18:07:57] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:07:57] root INFO: save model in ./output/cls/mv3/iter_epoch_5 [2021/05/27 18:07:57] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:08:31] root INFO: epoch: [6/100], iter: 29, lr: 0.000996, loss: 0.014210, acc: 1.000000, reader_cost: 3.27078 s, batch_cost: 3.39277 s, samples: 75, ips: 2.21059 [2021/05/27 18:08:31] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:08:31] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:09:01] root INFO: epoch: [7/100], iter: 30, lr: 0.000996, loss: 0.012825, acc: 1.000000, reader_cost: 3.01746 s, batch_cost: 3.04594 s, samples: 15, ips: 0.49246 [2021/05/27 18:09:17] root INFO: epoch: [7/100], iter: 34, lr: 0.000994, loss: 0.008651, acc: 1.000000, reader_cost: 1.52031 s, batch_cost: 1.61292 s, samples: 60, ips: 3.71997 [2021/05/27 18:09:17] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:09:17] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:10:01] root INFO: epoch: [8/100], iter: 39, lr: 0.000991, loss: 0.005914, acc: 1.000000, reader_cost: 4.24842 s, batch_cost: 4.36678 s, samples: 75, ips: 1.71751 [2021/05/27 18:10:01] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:10:01] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:10:27] root INFO: epoch: [9/100], iter: 40, lr: 0.000991, loss: 0.005617, acc: 1.000000, reader_cost: 2.54572 s, batch_cost: 2.57305 s, samples: 15, ips: 0.58296 [2021/05/27 18:10:39] root INFO: epoch: [9/100], iter: 44, lr: 0.000988, loss: 0.004479, acc: 1.000000, reader_cost: 1.12126 s, batch_cost: 1.21482 s, samples: 60, ips: 4.93900 [2021/05/27 18:10:39] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:10:39] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] [2021/05/27 18:11:14] root INFO: epoch: [10/100], iter: 49, lr: 0.000985, loss: 0.003660, acc: 1.000000, reader_cost: 3.32667 s, batch_cost: 3.44626 s, samples: 75, ips: 2.17627 [2021/05/27 18:11:14] root INFO: save model in ./output/cls/mv3/latest [2021/05/27 18:11:14] root INFO: save model in ./output/cls/mv3/iter_epoch_10 [2021/05/27 18:11:14] root INFO: Initialize indexs of datasets:['./train_data/cls/train.txt'] 等等

WenmuZhou commented 3 years ago

图片太少,过拟合了,并且,你训练四个角度的话,建议backbone改成从paddleclas里找一个,自带的是识别的backbone,适用于长条形的数据,你四个角度,shape需要弄成224*224这种正方形的

gavin2059 commented 3 years ago

谢谢,我去看看改个backbone。 不过就算图不够的话也不应该始终acc=1吧?这个我有点想不明白。 而且训练完,让他识别我训练时候用的图,识别也是错的(不管是什么他都识别成0),所以我觉着没有过拟合,而是根本没训练出来。。。

WenmuZhou commented 3 years ago

训练不出来的话,也不至于一直是1,你先换backbone试试