Python 输入与 input_signature 不兼容是什么意思

What does mean Python inputs incompatible with input_signature

我遇到了问题

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'))

您正在尝试将 4 通道图像馈送到具有 3 通道输入的 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)