简体   繁体   English

/ image / Tensor Tensor上的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float32)不是此图的元素

[英]ValueError at /image/ Tensor Tensor(“activation_5/Softmax:0”, shape=(?, 4), dtype=float32) is not an element of this graph

I am building an image processing classifier and this code is an API to predict the image class of the image the whole code is running except this line (pred = model.predict_classes(test_image)) this API is made in Django framework and am using python 2.7 我正在构建一个图像处理分类器,这段代码是一个API,用于预测整个代码运行的图像的图像类,除了这一行(pred = model.predict_classes(test_image))这个API是在Django框架中制作的,我正在使用python 2.7

here is a point if I am running this code like normally ( without making an API) it's running perfectly 如果我正常运行此代码(没有制作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)

Your test_image and input of tensorflow model is not match. 您的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)

The above is just assumption. 以上只是假设。 If you want to debug, i guess you should print your image size and compare with first layout of your model definition. 如果你想调试,我想你应该打印你的图像大小并与你的模型定义的第一个布局进行比较。 And check whe the size (width, height, depth) is match 并检查尺寸(宽度,高度,深度)是否匹配

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python - ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) 不是这个图的一个元素 - python - ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) is not an element of this graph Tensor Tensor("predictions/Softmax:0", shape=(?, 1000), dtype=float32) 不是这个图的元素 - Tensor Tensor("predictions/Softmax:0", shape=(?, 1000), dtype=float32) is not an element of this graph ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) 不是这个图的一个元素 - ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) is not an element of this graph Tensor(“dense_2/Softmax:0”, shape=(?, 10), dtype=float32) 不是该图的元素 - Tensor(“dense_2/Softmax:0”, shape=(?, 10), dtype=float32) is not an element of this graph ValueError:模型输出“Tensor(“activation_1/Identity:0”, shape=(?, 3), dtype=float32)”的形状无效 - ValueError: Model output "Tensor("activation_1/Identity:0", shape=(?, 3), dtype=float32)" has invalid shape ValueError: Tensor("ExponentialDecay_4:0", shape=(), dtype=float32) - ValueError: Tensor("ExponentialDecay_4:0", shape=(), dtype=float32) ValueError:Tensor(“ BN_1 / moments / Squeeze:0”,shape =(32,256,32),dtype = float32)必须与Tensor来自同一图 - ValueError: Tensor(“BN_1/moments/Squeeze:0”, shape=(32, 256, 32), dtype=float32) must be from the same graph as Tensor 无法将 feed_dict 键解释为 Tensor:Tensor Tensor("Placeholder:0", shape=(135162, 6), dtype=float32) 不是此图的元素 - Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(135162, 6), dtype=float32) is not an element of this graph ValueError:张量转换为具有 dtype float32 的张量请求 dtype float32_ref - ValueError: Tensor conversion requested dtype float32_ref for Tensor with dtype float32 ValueError:收到呼叫 arguments: • inputs=tf.Tensor(shape=(None, 1), dtype=float32) • training=None - ValueError : Call arguments received: • inputs=tf.Tensor(shape=(None, 1), dtype=float32) • training=None
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM