【发布时间】:2021-08-25 07:49:25
【问题描述】:
我想用flask API 上传图片,但是这段代码出错了。
def model_predict(img_path, model):
img = img_path
x = cv2.imdecode(np.fromstring(img.read(), np.uint8), cv2.IMREAD_UNCHANGED)
x = cv2.resize(x,(224,224))
x = np.expand_dims(x, axis=0)
images = np.vstack([x])/ 255.0
preds = model.predict(images)
if preds[0] > 0.5:
return "Good"
else:
return "Bad"
错误是
AttributeError: 'str' 对象没有属性 'read' 有什么解决办法吗?
【问题讨论】:
-
用你自己的话来说,你的代码是
img.read(),你期望img的值是多少?为什么?你测试过这个假设吗?当您为此致电.read()时,您认为会发生什么?为什么?
标签: python image csv flask cv2