Skip to content Skip to sidebar Skip to footer

Image Over Image Convolution In Tensorflow

Assume, I have two set of images, A and B, each 11X5x5x3, where 11 is a number of examples and 5x5x3 is an image dimension. Is there an easy way in Tensorflow to apply convolution

Solution 1:

I am not sure that is what you need because it is not really batch mode but you could use a map function :

A = tf.placeholder(dtype=tf.float32, shape=[None, 5, 5, 3])
B = tf.placeholder(dtype=tf.float32, shape=[None, 5, 5, 3])

output = tf.map_fn(
    lambda inputs : tf.nn.conv2d(
        tf.expand_dims(inputs[0], 0),  # H,W,C -> 1,H,W,C
        tf.expand_dims(inputs[1], 3),  # H,W,C -> H,W,C,1
        strides=[1,1,1,1],
        padding="SAME"
    ),  # Result of conv is 1,H,W,1
   elems=[A,B],
   dtype=tf.float32
)
final_output = output[:, 0, :, :, 0]  # B,1,H,W,1 -> B,H,W

Performance will depend on how the tiny separate convolutions will be parallelized I guess.

Post a Comment for "Image Over Image Convolution In Tensorflow"