Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing CNN with tensorflow

I'm new in convolutional neural networks and in Tensorflow and I need to implement a conv layer with further parameters:

Conv. layer1: filter=11, channel=64, stride=4, Relu.

The API is following:

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

I understand, what is stride and that it should be [1, 4, 4, 1] in my case. But I do not understand, how should I pass a filter parameter and padding. Could someone help with it?

like image 579
alex Avatar asked Oct 29 '25 14:10

alex


1 Answers

At first, you need to create a filter variable:

W = tf.Variable(tf.truncated_normal(shape = [11, 11, 3, 64], stddev = 0.1), tf.float32)

First two fields of shape parameter stand for filter size, third for the number of input channels (I guess your images have 3 channels) and fourth for the number of output channels.

Now output of convolutional layer could be computed as follows:

conv1 = tf.nn.conv2d(input, W, strides = [1, 4, 4, 1], padding = 'SAME'), where padding = 'SAME' stands for zero padding and therefore size of the image remains the same, input should have size [batch, size1, size2, 3].

ReLU application is pretty straightforward:

conv1 = tf.nn.relu(conv1)
like image 97
Dmitriy Danevskiy Avatar answered Oct 31 '25 03:10

Dmitriy Danevskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!