PaddleX载入模型预测报错
收藏
错误信息如下所示,感觉是代码没有问题啊。
主要就一是载入模型,二是进行预测,结果就错了找不到原因
import paddlex as pdx
import imageio
import os
import matplotlib.pyplot as plt
%matplotlib inline
%cd ~
model = pdx.load_model('output/mobilenetv3_small_ssld/best_model')
image_name = r'~/dataset/images/Images/n02085620-Chihuahua/n02085620_10074.jpg'
if not os.access(image_name, os.F_OK):
print("file has not exist!")
print(image_name)
im = imageio.imread(image_name)
plt.imshow(im)
plt.show()
result = model.predict(image_name)
print("Predict Result:", result)
---------------------------------------------------------------------------AttributeError Traceback (most recent call last) in
14 plt.imshow(im)
15 plt.show()
---> 16 result = model.predict(image_name)
17 print("Predict Result:", result)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlex/cv/models/classifier.py in predict(self, img_file, transforms, topk)
353 self.model_type,
354 self.__class__.__name__,
--> 355 input_channel=input_channel)
356
357 with fluid.scope_guard(self.scope):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlex/cv/models/classifier.py in _preprocess(images, transforms, model_type, class_name, thread_pool, input_channel)
307 batch_data = list()
308 for image in images:
--> 309 batch_data.append(transforms(image))
310 padding_batch = generate_minibatch(batch_data)
311 im = np.array([data[0] for data in padding_batch])
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlex/cv/transforms/cls_transforms.py in __call__(self, im_file, label)
88 raise TypeError('Can\'t read The image file {}!'.format(
89 im_file))
---> 90 self.data_type = im.dtype
91 im = im.astype('float32')
92 if input_channel == 3 and self.to_rgb:
AttributeError: 'NoneType' object has no attribute 'dtype'
0
收藏
请登录后评论
请更新paddlex至1.3.9,加载模型预测可以参考 https://paddlex.readthedocs.io/zh_CN/develop/train/prediction.html。
predict()对输入im的格式说明,可以参考 https://paddlex.readthedocs.io/zh_CN/develop/apis/models/classification.html#predict
漂亮