首页 / PYTHON / python – / image / Tensor Tensor的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float3
python – / image / Tensor Tensor的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float3
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – / image / Tensor Tensor的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float3,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1525字,纯文字阅读大概需要3分钟。
内容图文
![python – / image / Tensor Tensor的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float3](/upload/InfoBanner/zyjiaocheng/714/fd4e05d4e06549c5a5701733c393873c.jpg)
我正在构建一个图像处理分类器,这段代码是一个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)
解决方法:
您的test_image和tensorflow模型的输入不匹配.
# Your image shape is (, , 3)
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')
# Your image shape is (, , 4)
test_image = np.expand_dims(test_image, axis=0)
print(test_image)
print(test_image.shape)
pred = model.predict_classes(test_image)
以上只是假设.如果你想调试,我想你应该打印你的图像大小并与你的模型定义的第一个布局进行比较.并检查尺寸(宽度,高度,深度)是否匹配
内容总结
以上是互联网集市为您收集整理的python – / image / Tensor Tensor的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float3全部内容,希望文章能够帮你解决python – / image / Tensor Tensor的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float3所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。