Skip to content

Commit

Permalink
added tf cnn param calc
Browse files Browse the repository at this point in the history
  • Loading branch information
ZER-0-NE committed Mar 29, 2020
1 parent eda1f0a commit 4f67132
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Binary file added assets/param_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/param_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 61 additions & 1 deletion tf-practice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a repo I use often to brush up my skills in Tensorflow and to learn and

You can run all the scripts/notebooks individually by having all the required dependencies installed in your machine. Please note that you should have all the other scripts in your same local directory in order for the imports to work properly.

## Calculating number of parameters in Feed-forward Neural Networks:
## Calculating the number of parameters in Feed-forward Neural Networks:

Let,
- i, input size
Expand Down Expand Up @@ -70,6 +70,66 @@ model = Sequential([
])
```

## Calculating the number of parameters in Convolutional Neural Networks:

Let,
- i, no. of input maps (or channels)
- f, filter size/dimensions of the filter
- o, no. of output maps

For one conv layer, num_params
= weights + biases

`num_params = [i x (fxf) x o] + o`

#### Example 1:


<p align="center">
<img src=/assets/param_3.png/>
</p>


Here, i = 1 (only one channel); f = 2; o = 3

num_params = weights + biases

= [1 x (2x2) x 3] + 3

= 15 (There are 15 parameters viz., 12 weights and 3 biases)

Building such a sequential model would look something like:

```
model = Sequential([
Conv2D(3, (2,2), input_shape = (None, None, 1))
])
```

#### Example 2:


<p align="center">
<img src=/assets/param_4.png/>
</p>


Here, i = 3 (three channels); f = 2; o = 1

num_params = weights + biases

= [3 x (2x2) x 1] + 1

= 13 (There are 13 parameters viz., 12 weights and 1 bias)

Building such a sequential model would look something like:

```
model = Sequential([
Conv2D(1, (2,2), input_shape = (None, None, 3))
])
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Expand Down

0 comments on commit 4f67132

Please sign in to comment.