paddleocr ‘bytes‘ object has no attribute ‘shape‘

x33g5p2x  于2022-02-09 转载在 其他  
字(1.3k)|赞(0)|评价(0)|浏览(551)

paddleocr 训练reg时报错:

paddleocr 'bytes' object has no attribute 'shape'

[2022/02/08 21:15:54] root ERROR: When parsing line imgs/Pic_2022_01_09_111159_11.jpg 50kg

目前判断的原因是读图,

读图代码:

  1. with open(data['img_path'], 'rb') as f:
  2. img = f.read()
  3. data['image'] = img

然后DecodeImage,

在配置文件中配置:rec_chinese_lite_train_v2.0.yml

  1. Train:
  2. dataset:
  3. name: SimpleDataSet
  4. data_dir: F:/project/jushi/data/shuini/0208
  5. label_file_list: ["F:/project/jushi/data/shuini/0208/train_label.txt"]
  6. transforms:
  7. # - DecodeImage: # load image
  8. # img_mode: BGR
  9. # channel_first: False
  10. - RecAug:
  11. - CTCLabelEncode: # Class handling label
  12. - RecResizeImg:
  13. image_shape: [3, 32, 360]
  14. - KeepKeys:
  15. keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order

报错代码:

  1. def resize_norm_img(img, image_shape, padding=True):
  2. imgC, imgH, imgW = image_shape
  3. h = img.shape[0]
  4. w = img.shape[1]

怀疑 原来读取图片后是byte字符串,没有decode,就进入了读图片:

  1. # with open(data['img_path'], 'rb') as f:
  2. # img = f.read()
  3. # data['image'] = img
  4. data['image'] = cv2.imread(data['img_path'])

config文件:

  1. Train:
  2. dataset:
  3. name: SimpleDataSet
  4. data_dir: F:/project/jushi/data/shuini/0208
  5. label_file_list: ["F:/project/jushi/data/shuini/0208/train_label.txt"]
  6. transforms:
  7. # - DecodeImage: # load image
  8. # img_mode: BGR
  9. # channel_first: False

目前没有再报错了。

还需要改的地方:

  1. infer_rec.py

  1. infer_det.py
  1. # with open(file, 'rb') as f:
  2. # img = f.read()
  3. data = {'image': cv2.imread(file)}

相关文章