paddleocr ‘bytes‘ object has no attribute ‘shape‘

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

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

目前判断的原因是读图,

读图代码:

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

然后DecodeImage,

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

Train:
  dataset:
    name: SimpleDataSet
    data_dir: F:/project/jushi/data/shuini/0208
    label_file_list: ["F:/project/jushi/data/shuini/0208/train_label.txt"]
    transforms:
#      - DecodeImage: # load image
#          img_mode: BGR
#          channel_first: False
      - RecAug: 
      - CTCLabelEncode: # Class handling label
      - RecResizeImg:
          image_shape: [3, 32, 360]
      - KeepKeys:
          keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order

报错代码:

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

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

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

data['image'] = cv2.imread(data['img_path'])

config文件:

Train:
  dataset:
    name: SimpleDataSet
    data_dir: F:/project/jushi/data/shuini/0208
    label_file_list: ["F:/project/jushi/data/shuini/0208/train_label.txt"]
    transforms:
#      - DecodeImage: # load image
#          img_mode: BGR
#          channel_first: False

目前没有再报错了。

还需要改的地方:

infer_rec.py

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

相关文章

微信公众号

最新文章

更多