Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How exactly Convolution2D layer works in Keras?

I want to write own convolution layer same as Convolution2D. How it works in Keras? For example, if Convolution2D(64, 3, 3, activation='relu', input_shape=(3,226,226) Which equation will be for output data?

like image 211
Denzelmon Avatar asked Dec 16 '16 06:12

Denzelmon


People also ask

How does a Conv2D layer work?

Conv2D class. 2D convolution layer (e.g. spatial convolution over images). This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs. If use_bias is True, a bias vector is created and added to the outputs.

How does keras layers work?

Keras Layers are the functional building blocks of Keras Models. Each layer is created using numerous layer_() functions. These layers are fed with input information, they process this information, do some computation and hence produce the output. Further, this output of one layer is fed to another layer as its input.

What does Upsampling layer do?

The Upsampling layer is a simple layer with no weights that will double the dimensions of input and can be used in a generative model when followed by a traditional convolutional layer.

What is Conv2D layer in keras?

Keras Conv2D is a 2D Convolution Layer, this layer creates a convolution kernel that is wind with layers input which helps produce a tensor of outputs.


2 Answers

Since you input image shape is (266, 266, 3)[tf]/(3, 266, 266)[th], and the filter number is 64, and the kernel size is 3x3, and for padding, I think the default padding is 1, and the default stride is 1.

So, the output is 266x266x64.

output_width=output_height=(width – filter + 2*padding)/stride + 1

in your code, the width=266, the filter=3, the padding=1, and stride=1.

If you have any trouble understanding the basic concepts, I think you can read this cs231n post for more information.

For how to understanding the process of conv, click here.

like image 118
GoingMyWay Avatar answered Oct 21 '22 22:10

GoingMyWay


Actually, Keras is not doing a convolution in conv2d. In order to speed up the process, the convolution operation is converted into a matrix (row-per-column) multiplication. More info here, at chapter 6.

like image 27
Giuseppe Pezzano Avatar answered Oct 22 '22 00:10

Giuseppe Pezzano