How exactly Convolution2D layer works in Keras?
Asked Answered
L

2

7

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?

Lipid answered 16/12, 2016 at 6:22 Comment(2)
Keras is built on top of Tensorflow and Theano. What do you mean by "to write own convolution"? Do you want to implement a convolutional layer with means of Tensorflow/Theano or from scratch?Irreligion
I want to write own cnn lib, but for test use pre-trainded Keras or Tensorflow model. I want to figure out how these libs use input data and weights in convolution layer to get output data.Lipid
I
9

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.

Incogitant answered 16/1, 2017 at 3:53 Comment(0)
T
1

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.

Thermotensile answered 20/4, 2021 at 13:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.