Python输入与输入_签名不兼容是什么意思

2024-05-18 16:17:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我明白了

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

Tags: imageinputtfwithnpfnsignaturetensor
1条回答
网友
1楼 · 发布于 2024-05-18 16:17:45

您正在尝试使用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)

相关问题 更多 >

    热门问题