mindspore-lab / mindocr

A toolbox of ocr models and algorithms based on MindSpore

Home Page:https://mindspore-lab.github.io/mindocr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

【需求】支持自定义配置,自定义字典的预测

panxua opened this issue · comments

当前推理的网络构建使用如下接口

self.model = build_model(model_name, pretrained=pretrained, ckpt_load_path=ckpt_load_path, amp_level=amp_level)

貌似仅支持硬编码的如下配置
https://github.com/mindspore-lab/mindocr/blob/25bd212875bf5035c0ac3b015181cab4ee6276f0/tools/infer/text/predict_rec.py#L32C1-L38C2
自定义字典,改变输出序列长度后不能使用该脚本推理,能否提供支持自定义配置的接口以及指导。

本问题已由 #648 解决 ,现在可以通过tools/infer/text/predict_from_yaml.py脚本完成自定义的推理,具体说明请看文档tools/infer/text/README.MD

  1. 以自定义configs/rec/crnn/crnn_vgg7.yaml为例,通过自定义predict字段,定义模型预测的各参数。

predict:
  ckpt_load_path: ./tmp_rec/best.ckpt
  vis_font_path: tools/utils/simfang.ttf
  dataset_sink_mode: False
  dataset:
    type: PredictDataset
    dataset_root: path/to/dataset_root
    data_dir: predict_result/crop
    sample_ratio: 1.0
    shuffle: False
    transform_pipeline:
      - DecodeImage:
          img_mode: RGB
          to_float32: False
      - RecResizeNormForInfer:
          target_height: 32
          target_width: 100
          keep_ratio: False
          padding: False
          norm_before_pad: False
      - ToCHWImage:
    #  the order of the dataloader list, matching the network input and the input labels for the loss function, and optional data for debug/visaulize
    output_columns: ['image', 'img_path']
    net_input_column_index: [0] # input indices for network forward func in output_columns
    # label_column_index: [1, 2] # input indices marked as label

  loader:
      shuffle: False # TODO: tbc
      batch_size: 2
      drop_remainder: True
      max_rowsize: 12
      num_workers: 8
  1. 使用python tools/infer/text/predict_from_yaml.py. -image_dir xxx --rec_config configs/rec/crnn/crnn_vgg7.yaml --mode rec 完成推理。

@panxua 您好,感谢您的问题反馈。自定义字典功能已开发支持,本issue将暂时关闭,如有进一步的问题或需求,请与我们联系。