【发布时间】:2021-05-20 17:37:20
【问题描述】:
我有以下代码,旨在查找像素强度 >= 25 的第一个和最后一个像素,然后裁剪到该边界框:
white_pixels = tf.where(input_img >= 25)
first_white_pixel = white_pixels[:, 0]
first_white_pixel = tf.cast(first_white_pixel, dtype=tf.int32)
last_white_pixel = white_pixels[:, -1]
last_white_pixel = tf.cast(last_white_pixel, dtype=tf.int32)
cropped = tf.image.crop_to_bounding_box(input_img, first_white_pixel[0], 0, last_white_pixel[0] - first_white_pixel[0], 299)
但是,我不断收到错误消息,指出 tf.image.crop_to_bounding_box 中的 target_height 必须高于 0。在我所有的图像中,last_white_pixel[0] - first_white_pixel[0] 的结果肯定高于 0。代码是在 TensorFlow 2.3 中作为符号张量执行,并且在非符号设置中工作正常(因为缺少更好的术语)。
【问题讨论】:
标签: python tensorflow2.0 tensor