Reputation: 521
I want to split an image in to two pieces so that I can process the first piece on GPU #1 and the second piece on GPU #2. Here's the problem, though: I can't seem to split the image in half
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)
Now comes the tricky part. How do I split the image in half? Here is pseudo code of what I want to do
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])
I've tried to get the image shape using image_float32.get_shape().as_list()
, which returns [None,None,3]
. I've also tried x=tf.shape(image_float32)[0]
, but that returns
TypeError: int() argument must be a string or a number, not 'Tensor'
I know about tf.split
, but I don't know how to split the image in the way I want in my pseudo code. Any ideas?
Upvotes: 1
Views: 709
Reputation: 4918
you can use tf.slice
first_half = tf.slice(image, [0, 0, 0], [a, y, z])
second_half = tf.slice(image, [a, 0, 0], [b, y, z])
Upvotes: 1