Using a custom filter in convolution layer for tensorflow

1,168 views
Skip to first unread message

ivans....@gmail.com

unread,
Jun 27, 2016, 5:24:05 PM6/27/16
to Discuss

I've been learning Tensorflow from a variety of tutorials and am wondering if it's possible to define a custom filter for convolution nets to use. For example, if I know there is meaningful structure in the features, such that every other feature is related, I want to define a filter that looks like [0 1 0  1].


tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)

All the examples I've seen so far use:

tf.random_normal

or

tf.truncated_normal

for the filter argument. Can I and does it make sense for me to put [0 1 0 1] in the filter argument instead?


Many thanks!

Frédéric Branchaud-Charron

unread,
Jun 28, 2016, 10:39:21 AM6/28/16
to Discuss, ivans....@gmail.com
Hi Ivan!
Your filter doesn't make sense since it's a 1d Tensor. But, if you have a filter with a shape that could fit in the conv2d layer (for exemple shape could be [3,3,64]) you could totally use it.
Generate your numpy array : w = np.array[,,,]
Create a variable 
kernel = tf.Variable(w.astype(np.float32))

and create your layer
conv = tf.nn.conv2d(input.kernel,...)

Hope this help!
Reply all
Reply to author
Forward
0 new messages