【发布时间】:2018-04-27 22:43:55
【问题描述】:
我正在构建一个图像处理分类器,此代码是一个 API,用于预测整个代码正在运行的图像的图像类,除了这一行 (pred = model.predict_classes(test_image)) 此 API 是在 Django 框架中制作的,并且我正在使用 python 2.7
如果我像往常一样运行此代码(不创建 API),那么它运行良好
def classify_image(request):
if request.method == 'POST' and request.FILES['test_image']:
fs = FileSystemStorage()
fs.save(request.FILES['test_image'].name, request.FILES['test_image'])
test_image = cv2.imread('media/'+request.FILES['test_image'].name)
if test_image is not None:
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)
else:
print('image didnt load')
test_image = np.expand_dims(test_image, axis=0)
print(test_image)
print(test_image.shape)
pred = model.predict_classes(test_image)
print(pred)
return JsonResponse(pred, safe=False)
【问题讨论】:
-
你如何定义model?或许本期类似问题的评论可以帮到你:Tensorflow backend - bug
-
没有型号
标签: python django machine-learning tensorflow keras