首页 > 解决方案 > 在 keras 模型中输入时,我的输入 np 数组变成不同的形状

问题描述

图像的形状为,(512, 2048, 3)但运行时出现 ValueError preds_train = new_model.predict(img, batch_size=1)

ValueError: Could not find matching function to call loaded from the SavedModel. Got:
  Positional arguments (3 total):
    * Tensor("inputs:0", shape=(1, 2048, 3), dtype=float32)
    * False
    * None
  Keyword arguments: {}

Expected these arguments to match one of the following 4 option(s):

Option 1:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 512, 2048, 3), dtype=tf.float32, name='inputs')
    * True
    * None
  Keyword arguments: {}

Option 2:
  Positional arguments (3 total):
    * True
    * None
  Keyword arguments: {}

Option 3:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 512, 2048, 3), dtype=tf.float32, name='input_1')
    * False
    * None
  Keyword arguments: {}

Option 4:
  Positional arguments (3 total):
    * TensorSpec(shape=(None, 512, 2048, 3), dtype=tf.float32, name='inputs')
    * False
    * None
  Keyword arguments: {}

我已经打印了形状的初始尺寸,所以我确定它是(512, 2048, 3),另外,当我训练模型时,我使用该形状的图像这样做。我不知道为什么我不能测试模型。

标签: pythontensorflowkeras

解决方案


尝试使用 model.evaluate(x_test)


推荐阅读