【发布时间】:2018-04-27 18:25:42
【问题描述】:
我已经构建了一个图像处理分类器,在这段代码中,我正在制作一个 api,它采用输入图像表单键“test_image”并预测图像的类别,但 cv2.imread() 给了我这个错误
TypeError at /image/ 预期字符串或 Unicode 对象,找到 InMemoryUploadedFile
我知道cv2.imread 只获取图片的网址,但我不知道如何解决。
我的代码:
def classify_image(request):
if request.method == 'POST' and request.FILES['test_image']:
test_image = request.FILES['test_image']
test_image = cv2.imread(test_image)
test_image = cv2.resize(test_image, (128, 128))
test_image = np.array(test_image)
test_image = test_image.astype('float32')
test_image /= 255
print(test_image.shape)
test_image = np.expand_dims(test_image, axis=0)
pred = model.predict_classes(test_image)
print(pred)
return JsonResponse(pred, safe=False)
【问题讨论】:
标签: python django opencv machine-learning