Reputation: 1139
I would like to convolve over my data feed with filters of different sizes and was wondering how I can achieve the following setup using Tensorflow
In other words, I would like to have two parallel convolutions and connect them in the flattening layer, right before feeding into the fully connected layer but am unsure about the connections.
Any code snippet or sources on approach would tremendously help!
Upvotes: 1
Views: 1079
Reputation: 5844
Assume batch size 100 and image data of size 28x28x1.
import tensorflow as tf
inp = tf.placeholder(tf.float32, shape=[100, 28, 28, 1])
left_branch = tf.layers.conv2d(input=inp, filters=N, kernel_size=[L, M])
right_branch = tf.layers.conv2d(input=inp, filters=P, kernel_size=[R, S])
left_reshape = tf.reshape(left_branch, [100, num_outputs_in_left_branch])
right_reshape = tf.reshape(right_branch, [100, num_outputs_in_right_branch])
combined_branch = tf.concat([left_reshape, right_reshape], axis=1)
combined_branch = tf.layers.dense(combined_branch, num_units_in_dense)
Upvotes: 2