2017-08-29 64 views
0

我想將圖像分成兩部分,這樣我可以在GPU#1上處理第一塊,在GPU#2上處理第二塊。這裏的問題,但我似乎無法在圖像半Tensorflow - 如何將圖像分成一半?

with tf.device(my_gpu): 

    # Load onto GPU 
    filename_queue = tf.train.string_input_producer([image_path], capacity=1) 
    reader = tf.WholeFileReader() 
    key, value = reader.read(filename_queue) 

    # Get image as float32 
    image = tf.image.decode_png(value, channels=3) 
    image_float32 = tf.image.convert_image_dtype(image, tf.float32) 

拆分現在到了棘手的部分。我如何將圖像分成一半?這裏是什麼,我想要做的

x,y,z = image.shape 
half = x/2 

a = half - 3 
b = half + 3 

first_half = image[:b, :, :] 
second_half = image[a:, :, :] 

batch1 = tf.stack([first_half]) 
batch2 = tf.stack([second half]) 

我試圖讓使用image_float32.get_shape().as_list()圖像形狀,它返回[None,None,3]僞代碼。我也試過x=tf.shape(image_float32)[0],但返回

TypeError: int() argument must be a string or a number, not 'Tensor' 

我知道tf.split,但我不知道如何將圖像中我想在我的僞代碼的方式分割。有任何想法嗎?

回答

0

可以使用tf.slice

first_half = tf.slice(image, [0, 0, 0], [a, y, z]) 
second_half = tf.slice(image, [a, 0, 0], [b, y, z]) 
+0

你是怎麼找到A,B,Y和Z?代碼示例,不是僞代碼。 – giusva