【问题标题】:What does mean Python inputs incompatible with input_signaturePython 输入与 input_signature 不兼容是什么意思
【发布时间】:2021-03-04 10:08:08
【问题描述】:

我遇到了问题

ValueError: Python inputs incompatible with input_signature:

当我这样做时:

image_np = np.asarray(np.array(Image.open(image_path)))
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
detections = detect_fn(input_tensor)

问题恰好发生在这一行:

detections = detect_fn(input_tensor)

我做错了什么?这个错误是什么意思?

控制台日志

ValueError: Python inputs incompatible with input_signature:
  inputs: (
    tf.Tensor(
[[[[255 255 255 255]
   [255 255 255 255]
   [255 255 255 255]
   ...
   [255 255 255 255]
   [255 255 255 255]
   [255 255 255 255]]

  [[254 254 254 255]
   [255 255 255 255]
   [255 255 255 255]
   ...
   [255 255 255 255]
   [255 255 255 255]
   [255 255 255 255]]

  [[254 254 254 255]
   [254 254 255 255]
   [255 255 255 255]
   ...
   [255 255 255 255]
   [255 255 255 255]
   [255 255 255 255]]

  ...

  [[ 37  37  37 255]
   [ 37  37  37 255]
   [ 39  39  39 255]
   ...
   [ 32  32  32 255]
   [ 33  33  33 255]
   [ 31  31  31 255]]

  [[ 37  37  37 255]
   [ 38  38  38 255]
   [ 36  36  36 255]
   ...
   [ 33  33  33 255]
   [ 31  31  31 255]
   [ 32  32  32 255]]

  [[ 38  38  38 255]
   [ 37  37  37 255]
   [ 38  38  38 255]
   ...
   [ 32  32  32 255]
   [ 31  31  31 255]
   [ 32  32  32 255]]]], shape=(1, 1080, 1915, 4), dtype=uint8))
  input_signature: (
    TensorSpec(shape=(1, None, None, 3), dtype=tf.uint8, name='input_tensor'))

【问题讨论】:

  • 最后一个维度不同(模型为 3,输入为 4)
  • @Andrey 那么我该如何解决呢? last dimensions 是什么意思.. 对不起,我是 python 新手
  • 根据您的形状 - 我建议您尝试将 4 通道图像提供给为 3 通道创建的 NN。如果是这样 - 您可能必须删除一个频道。或查找具有 4 个通道的型号
  • @Andrey 你将如何删除频道?

标签: python tensorflow2.0 tensor


【解决方案1】:

您正在尝试使用 3 通道输入将 4 通道图像馈送到 NN。删除最后一个频道:

image_np = np.asarray(np.array(Image.open(image_path)))
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
input_tensor = input_tensor[:, :, :, :3] # <= add this line
detections = detect_fn(input_tensor)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-19
    • 2013-07-01
    • 1970-01-01
    • 2021-04-04
    • 2021-01-04
    • 2020-08-17
    • 2020-09-11
    • 2020-06-23
    相关资源
    最近更新 更多