bisounours_tronconneuse bisounours_tronconneuse - 4 years ago 229
Python Question

Tensorflow: Convolutions with different filter for each sample in the mini-batch

I would like to have a 2d convolution with a filter which depends on the sample in the mini-batch in tensorflow. Any ideas how one could do that, especially if the number of sample per mini-batch is not known?

Concretely, I have input data

of the form
MB x H x W x Channels
, and I have filters
of the form
MB x fh x fw x Channels x OutChannels

It is assumed that

inp = tf.placeholder('float', [None, H, W, channels_img], name='img_input')

I would like to do
tf.nn.conv2d(inp, F, strides = [1,1,1,1])
, but this is not allowed because
cannot have a mini-batch dimension. Any idea how to solve this problem?

Answer Source

They way to go around it is adding an extra dimension using

tf.expand_dims(inp, 0)

to create a 'fake' batch size. Then use the


operation where the filter-depth matches the batch size. This will result in each filter convolving with only one sample in each batch.

Sadly, you will not solve the variable batch size problem this way, only the convolutions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download