/ image / Tensor Tensor( "activation_5 / Softmax:0"、shape =(?, 4)、dtype = float32)のValueErrorは、このグラフの要素ではありません

デクスター

私は画像処理分類子を構築しています。このコードは、この行(pred = model.predict_classes(test_image))を除いて、コード全体が実行されている画像の画像クラスを予測するAPIです。この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)
Vu Gia Truong

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)

上記は単なる仮定です。デバッグしたい場合は、画像サイズを印刷して、モデル定義の最初のレイアウトと比較する必要があると思います。そして、サイズ(幅、高さ、奥行き)が一致しているかどうかを確認します

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ