1
$\begingroup$

I have a convolutional layer $g$ with 10 feature maps given by: $$g(x^i) = \sigma([z_1,z_2,\dots,z_{10}])$$ where $z_j = x^i \cdot w_j$ for some convolutional kernel $w_j$ of size 3. Each $x^i$ is padded with a zero at each end. And $x_i$ is a set of 1-D signals in $R^{100}$.

I'm trying to find the number of trainable parameters in this layer using Keras.


from keras.models import Sequential
from keras.layers import Conv2D, Dense

model = Sequential()
model.add(Conv2D(filters = 10,
                 kernel_size = (3,3),
                 input_shape = (1000,100,1),
                 use_bias = False))
model.summary()


Output :
----------
Model: "sequential_26"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_22 (Conv2D)           (None, 998, 98, 10)       90        
=================================================================
Total params: 90
Trainable params: 90
Non-trainable params: 0

Am I creating the correct arguments in Keras for this convolutional layer? I think the actual amount of trainable parameters is 30? But i dont know what to place for the arguments. Could someone also give me intuition to the actual number of learnable parameters? Thanks.

$\endgroup$

1 Answer 1

1
$\begingroup$

You've specified 10 filters in a 2d convolution, each of size $3\times 3$ so you have $3 \times 3 \times 10=90$ trainable parameters.

You have 1d data, but you're using a 2d convolution. Perhaps this is a typo and you meant Conv1D?

$\endgroup$
6
  • $\begingroup$ was it correct to specify 10 filters? is $z$ a filter? $\endgroup$
    – Eisen
    Oct 15, 2020 at 22:37
  • $\begingroup$ It's not clear what you mean. From your notation, it looks like you mean to write that $z = f(x;w)$ is the output of a convolutional operation $f$ parameterized by by a filter $w$. Usually $a \cdot b$ is used to denote scalar multiplication or a dot product of $a$ with $b$, which is not the same as a convolution. $\endgroup$
    – Sycorax
    Oct 15, 2020 at 22:49
  • $\begingroup$ Apologies for the notation, that is what I mean. But should there only be 30 learnabble parameters? 3 for each of the 10 convolutions? $\endgroup$
    – Eisen
    Oct 15, 2020 at 22:57
  • $\begingroup$ No, there are 90 parameters for a 2d convolution of this size with this many filters. Perhaps you meant to use a 1d convolution? $\endgroup$
    – Sycorax
    Oct 15, 2020 at 23:04
  • 1
    $\begingroup$ It seems like you have a new question. It's best to ask a new Question on its own because comments are not large enough to fit all of the necessary information. In particular, you should elaborate on why you think that choice of input shape is not correct. $\endgroup$
    – Sycorax
    Oct 15, 2020 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.