TypeError://:'NoneType'和'int'的不支持的操作数类型

时间:2018-02-01 08:51:46

标签: python tensorflow object-detection

在投资回报率池中,您有一个感兴趣的区域(ROI),并且您希望将其汇集到特定大小。

ROI gif

我尝试在gif中实现相同的功能。 整个图像是

image_pl = tf.placeholder(dtype=tf.float32)  # the whole region

感兴趣的区域是

x = 0
y = 3
w = 7
h = -1
roi = tf.slice(image_pl, [x, y, 0], [w, h, -1])  # region of interest

现在我尝试获得4个部分,因为每个感兴趣的区域,无论大小,我都想裁剪到2x2的大小

w_roi = roi.get_shape()[0].value
h_roi = roi.get_shape()[1].value
roi_part1 = tf.slice(roi, [0, 0, 0], [w_roi // 2, h_roi // 2, -1]) # fisrt part from the gif
roi_part2 = tf.slice(roi, [w_roi - w_roi // 2, 0, 0], [w_roi, h_roi // 2, -1])  # second part from the gif
roi_part3 = tf.slice(roi, [0, h_roi - h_roi // 2, 0], [w_roi // 2, h_roi, -1])
roi_part4 = tf.slice(roi, [w_roi - w_roi // 2, h_roi - h_roi // 2, 0], [w_roi, h_roi, -1])

但在这里我得到了错误。

  

TypeError://不支持的操作数类型:'NoneType'和'int'

这是整个代码。 我怎样才能实现那个gif的想法?

import numpy as np
import tensorflow as tf

image_pl = tf.placeholder(dtype=tf.float32)  # the whole region

x = 0
y = 3
w = 7
h = -1
roi = tf.slice(image_pl, [x, y, 0], [w, h, -1])  # region of interest

w_roi = roi.get_shape()[0].value
h_roi = roi.get_shape()[1].value
roi_part1 = tf.slice(roi, [0, 0, 0], [w_roi // 2, h_roi // 2, -1]) # fisrt part from the gif
roi_part2 = tf.slice(roi, [w_roi - w_roi // 2, 0, 0], [w_roi, h_roi // 2, -1])  # second part from the gif
roi_part3 = tf.slice(roi, [0, h_roi - h_roi // 2, 0], [w_roi // 2, h_roi, -1])
roi_part4 = tf.slice(roi, [w_roi - w_roi // 2, h_roi - h_roi // 2, 0], [w_roi, h_roi, -1])

output1 = tf.reduce_max(roi_part1)  # maximum of the region 1 in the region of interest
output2 = tf.reduce_max(roi_part2)
output3 = tf.reduce_max(roi_part3)
output4 = tf.reduce_max(roi_part4)
output = tf.concat([output1, output2, output3, output4], 0)

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
with tf.Session(config=config) as sess:
    sess.run(tf.global_variables_initializer())
    image = np.random.uniform(0, 1, (8, 8, 1))
    curr_image, curr_roi, curr_output = sess.run([image_pl, roi, output], feed_dict={image_pl: image})

0 个答案:

没有答案