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

前端 未结 1 1274
忘掉有多难
忘掉有多难 2020-11-27 23:38

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

相关标签:
1条回答
  • 2020-11-28 00:15

    Your test_image and input of tensorflow model is not match.

    # 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

    0 讨论(0)
提交回复
热议问题