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
42.75k stars 7.68k forks source link

AssertionError: The length of ratio_list should be the same as the file_list. #1996

Closed jey07 closed 3 years ago

jey07 commented 3 years ago

May i know why I am getting below error while running text detection:

[2021/02/09 13:56:31] root INFO: train with paddle 2.0.0 and device CPUPlace
Traceback (most recent call last):
  File "tools/train.py", line 114, in <module>
    main(config, device, logger, vdl_writer)
  File "tools/train.py", line 52, in main
    train_dataloader = build_dataloader(config, 'Train', device, logger)
  File "/content/gdrive/My Drive/Paddle_OCR/PaddleOCR/ppocr/data/__init__.py", line 64, in build_dataloader
    dataset = eval(module_name)(config, mode, logger, seed)
  File "/content/gdrive/My Drive/Paddle_OCR/PaddleOCR/ppocr/data/simple_dataset.py", line 40, in __init__
    ) =**= data_source_num, "The length of ratio_list should be the same as the file_list."
AssertionError: The length of ratio_list should be the same as the file_list.**

I am using below command to train: python3 tools/train.py -c configs/det/det_r50_vd_sast_icdar15.yml

Below was my config file:

Global:
  use_gpu: false
  epoch_num: 5000
  log_smooth_window: 20
  print_batch_step: 2
  save_model_dir: ./output/sast_r50_vd_ic15/
  save_epoch_step: 1000
  # evaluation is run every 5000 iterations after the 4000th iteration
  eval_batch_step: [4000, 5000]
  # if pretrained_model is saved in static mode, load_static_weights must set to True
  load_static_weights: True
  cal_metric_during_train: False
  pretrained_model: ./pretrain_models/ResNet50_vd_ssld_pretrained/
  checkpoints: 
  save_inference_dir:
  use_visualdl: False
  infer_img: 
  save_res_path: ./output/sast_r50_vd_ic15/predicts_sast.txt

Architecture:
  model_type: det
  algorithm: SAST
  Transform:
  Backbone:
    name: ResNet_SAST
    layers: 50
  Neck:
    name: SASTFPN
    with_cab: True
  Head:
    name: SASTHead

Loss:
  name: SASTLoss

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

PostProcess:
  name: SASTPostProcess
  score_thresh: 0.5
  sample_pts_num: 2
  nms_thresh: 0.2
  expand_scale: 1.0
  shrink_ratio_of_width: 0.3

Metric:
  name: DetMetric
  main_indicator: hmean

Train:
  dataset:
    name: SimpleDataSet
    data_dir: ./train_data/icdar2015/text_localization/icdar_c4_train_imgs/
    label_file_list:
      - ./train_data/icdar2015/text_localization/train_icdar2015_label.txt
    ratio_list: [0.1, 0.45, 0.3, 0.15]
    transforms:
      - DecodeImage: # load image
          img_mode: BGR
          channel_first: False
      - DetLabelEncode: # Class handling label
      - SASTProcessTrain:
          image_shape: [512, 512]
          min_crop_side_ratio: 0.3
          min_crop_size: 24
          min_text_size: 4
          max_text_size: 512
      - KeepKeys:
          keep_keys: ['image', 'score_map', 'border_map', 'training_mask', 'tvo_map', 'tco_map'] # dataloader will return list in this order
  loader:
    shuffle: True
    drop_last: False
    batch_size_per_card: 4
    num_workers: 4

Eval:
  dataset:
    name: SimpleDataSet
    data_dir: ./train_data/icdar2015/text_localization/icdar_c4_train_imgs/
    label_file_list:
      - ./train_data/icdar2015/text_localization/test_icdar2015_label.txt
    transforms:
      - DecodeImage: # load image
          img_mode: BGR
          channel_first: False
      - DetLabelEncode: # Class handling label
      - DetResizeForTest:
          resize_long: 1536
      - NormalizeImage:
          scale: 1./255.
          mean: [0.485, 0.456, 0.406]
          std: [0.229, 0.224, 0.225]
          order: 'hwc'
      - ToCHWImage:
      - KeepKeys:
          keep_keys: ['image', 'shape', 'polys', 'ignore_tags']
  loader:
    shuffle: False
    drop_last: False
    batch_size_per_card: 1 # must be 1
    num_workers: 2
Ankan1998 commented 3 years ago

I am also facing the same issue. Do let me know, if your issue is solved

jey07 commented 3 years ago

basically...look at the ratio_list. If you dont have multiple training data then his issue may arise

kabu1204 commented 3 years ago

In ppocr/data/simple_dataset.py line 32: label_file_list = dataset_config.pop('label_file_list') , the variablelabel_file_list is supposed to be a python list. And in the next line, data_source_num = len(label_file_list), here is a problem. In your YML, if you pass label_file_list: ./train_data/icdar2015/text_localization/test_icdar2015_label.txt, the variablelabel_file_list in ppocr/data/simple_dataset.py will be a python string. And data_source_num will be something but 1, which not equals ratio_list. Solution pass label_file_list: [./train_data/icdar2015/text_localization/test_icdar2015_label.txt] in your YML file.

jitesh-rathod commented 3 years ago

i was facing same issue but solve..... label_file_list= ratio_list

paddle-bot-old[bot] commented 3 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。 若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。

thongvhoang commented 3 years ago

basically...look at the ratio_list. If you dont have multiple training data then his issue may arise

Thank you. I have same problems and I solved them.