Python ValueError:在使用tf.image.crop\u到\u bounding\u框时,Tensor转换为dtype float32的Tensor请求了dtype int32
我试图根据边界框裁剪图像Python ValueError:在使用tf.image.crop\u到\u bounding\u框时,Tensor转换为dtype float32的Tensor请求了dtype int32,python,tensorflow,image-processing,keras,Python,Tensorflow,Image Processing,Keras,我试图根据边界框裁剪图像 bbox = [{'width': '500', 'ymin': '125', 'depth': '3', 'xmax': '387', 'xmin': '29', 'height': '375', 'ymax': '245'}] ymin = float(bbox['ymin'])/float(bbox['height']) ymax = float(bbox['ymax'])/float(bbox['height']) xmin = float(bbox['xmi
bbox = [{'width': '500', 'ymin': '125', 'depth': '3', 'xmax': '387', 'xmin': '29', 'height': '375', 'ymax': '245'}]
ymin = float(bbox['ymin'])/float(bbox['height'])
ymax = float(bbox['ymax'])/float(bbox['height'])
xmin = float(bbox['xmin'])/float(bbox['width'])
xmax = float(bbox['xmax'])/float(bbox['width'])
total_height = tf.convert_to_tensor(ymax_int - ymin_int)
total_width = tf.convert_to_tensor(xmax - xmin)
ymin = tf.convert_to_tensor(ymin)
xmin = tf.convert_to_tensor(xmin)
img=mpimg.imread(filename)
img = tf.convert_to_tensor(img)
image = tf.image.crop_to_bounding_box(img, ymin, xmin, total_height, total_width)
我得到以下错误:
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype
float32: 'Tensor("Const_7:0", shape=(), dtype=float32)'
Const_7:0 is ymin
感谢TensorFlow使用任何有关如何修复此问题的帮助来裁剪图像,这需要将张量的数据类型总高度,总宽度,ymin
和xmin
设置为int32
:
total_height = tf.convert_to_tensor(ymax_int - ymin_int, dtype=tf.int32)
total_width = tf.convert_to_tensor(xmax - xmin, dtype=tf.int32)
ymin = tf.convert_to_tensor(ymin, dtype=tf.int32)
xmin = tf.convert_to_tensor(xmin, dtype=tf.int32)
尝试将total_height
变量设置为以下值:
total_height = tf.cast(tf.convert_to_tensor(ymax_int - ymin_int, dtype = tf.float32), dtype = tf.int32)
tf.convert\u to\u tensor(arg,dtype=tf.float32)
help?