Prashant Profile picture
Apr 17, 2021 14 tweets 4 min read Read on X
Calculating Convolution sizes is something that I found particularly hard after understanding convolutions for the first time.

I couldn't remember the formula because I didn't understand its working exactly.

So here's my attempt to get some intuition behind the calculation.🔣👇 Image
BTW if you haven't read the thread 🧵 on 1D, 2D, 3D CNN, you may want to check it out once.

First, observe the picture below🖼 Image
The 2 x 2 filter slides over the
3 rows, 2 times and,
4 columns, 3 times

So, let's try subtracting the filter size first
3 - 2 = 1
4 - 2 = 2

Looks short, we'll need to compensate the 1 in both.
3 - 2 + 1 = 2
4 - 2 + 1 = 3

hence the formula so far becomes: Image
Now let's discuss padding0⃣

Zero padding makes it possible to get output equal to the input by adding extra columns.

It provides extra space for the sliding, making up for the lost space Image
Padding of p would mean increasing the input size by adding p to both sides

Considering width, there will be padding for left and for right, both equal, same for the height.

The modified formula becomes Image
All of our calculation so far assumes that we are taking one step at a time during sliding, a stride of 1

What if we take more than that?🏃

We will be cutting our distance short by increasing the size of our leap. So to account for this we will divide with stride size. Image
Keep in mind that we should make sure that the calculation doesn't go into decimals.

We generally select our values in such a way that the calculations result in an integer.
Now as we may remember from the last thread, that one filter leads to 1 output, be it 1D, 2D...

So the depth of the output will be equal to the number of filters applied. Image
With all that in mind, let's try to solve a simple question below: Image
We can try the same using Keras and its functions. Image
This website is a ConvNet shape calculator with which you can play around a little bit for better understanding.

madebyollin.github.io/convnet-calcul…
Now if you feel like you can calculate correctly, try to pick any network and calculate its output sizes, validate using the model summary.

Or pick 3D convolutions and calculate its outputs, the principle remains the same.
All the above points helped me to be able to understand the CNN architectures better and not be bothered by the output summary.

Hope this helps you too! 👍 Image

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Prashant

Prashant Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @capeandcode

Feb 24, 2023
How ChatGPT Works?

• Everyone knows about ChatGPT but not everyone is aware of how it works.

Here is an attempt at explanation ↓

[ In 10 Steps ]
• It is a large language model based which uses a technique called "transformer" to understand and generate human-like responses to text-based input.

• Transformer is a neural network architecture that excels at processing sequential data, such as text.
• The model is trained on a massive amount of text data from a wide range of sources, such as books, articles, and websites.

• These resources allow the model to learn patterns and relationships in language.
Read 12 tweets
Sep 22, 2022
"Learn SQL"

Great advice no doubt.

• But what topics to cover?
• Which SQL database to use?
• What resources to learn from?

Here's is a track you can follow ↓

1/22
Let's start with choosing the SQL database to learn.

• There are several of databases like Postgres, MS SQL server, MS Access, Oracle.

• But for learning purposes I'd suggest going with MySQL.

• For reasons that it is secure, free & open source and the support is great.
• Later on we can switch to other databases easily.

• Now what topic should we know in SQL? I knew the basics like select, where and joins but I couldn't get past them.

• So here are some topics and terms everyone should learn, starting with...
Read 23 tweets
Sep 14, 2022
Interview Question:

• What is Covariance?
• What is Correlation?

• What are the differences between them?

Explain briefly ↓

0/9
COVARIANCE

• Covariance tells us the systematic relationship between two random variables, in which a change in one reflects the change in other.

• It measures the joint variability of two random variables.

• The formula for covariance is:

1/9
• It has a range of [-∞, +∞].

• The greater the covariance, the more reliant the relationship.

• The covariance value isn't very easy to interpret and depends on the context.

2/9
Read 11 tweets
Sep 12, 2022
Interview Questions

• How does k-means work?
• What are its stopping criteria?
• What are its pros and cons?
• How do you choose its number of clusters?

Explain briefly ↓

0/4 Image
1. Working

• k-means is an unsupervised algorithm.

• We want to create groups of similar data points using this algorithm.
• In k-means we begin with a set of random points as clusters.

• We measure the distance of each point from the clusters using some distance metric like euclidean or cosine.

• We assign points to the cluster that is closest to it.
Read 11 tweets
Sep 2, 2022
Another common interview question

• What are the assumptions of Linear Regression?
• How do we check them?
• How can we fix them?

Here's the answer ↓

0/5
1. Linear Relationship

It is assumed that the relationship between the dependent and independent variables is linear.
!How to check:

• Observe the Residuals vs Fitted Value plots, there shouldn't be any evident pattern.
Read 17 tweets
Aug 31, 2022
Random Forests is a favorite for interviews!

By far the most common questions that I have been asked are one way or other related to Random Forests

It's important to know it inside out.

Here's are some of those questions:

0/8
Q: What ensemble principle is used in Random Forests?

A: Random Forest works on the principle of the bagging ensemble technique.

Bagging stands for Bootstrap Aggregation.
In Bagging, random data samples in a training set are used with replacement.

1/9
Q: Do Random Forests require pruning?

A: Random Forests usually do not require pruning as they don't overfit like a single DT as trees are bootstrapped and multiple random trees use random features so the individual trees are strong predictors without being correlated.

2/9
Read 15 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(