Lecture 4: Image Classification with Convolutional Neural Networks

Session Recordings:
English: https://youtu.be/d9QHNkD_Pos
Hindi: https://youtu.be/OTyv_G3OL9I

This lesson introduces convolutional neural networks (CNNs) that are well-suited for image datasets and computer vision problems. We also cover underfitting, overfitting and techniques to improve model performance. Notebooks used in this lesson:

Asking/Answering Questions :
Reply to this thread to ask questions. Before asking, scroll through the thread and check if your question (or a similar one) is already present. If yes, just like it. We will give priority to the questions with the most likes. The rest will be answered by our mentors or the community. If you see a question you know the answer to, please post your answer as a reply to that question. Let’s help each other learn!

Hi Team,

I was trying to build an CNN on the Intel dataset set.
I am getting an following error which i am not able to resolve.

Please find link to my notebook. Would appreciate any assistance
link - https://jovian.ai/hargurjeet/intel-image-classification

RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py”, line 198, in _worker_loop
data = fetcher.fetch(index)
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py”, line 47, in fetch
return self.collate_fn(data)
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py”, line 83, in default_collate
return [default_collate(samples) for samples in transposed]
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py”, line 83, in
return [default_collate(samples) for samples in transposed]
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/collate.py”, line 55, in default_collate
return torch.stack(batch, 0, out=out)
RuntimeError: stack expects each tensor to be equal size, but got [3, 150, 150] at entry 0 and [3, 124, 150] at entry 32

simple_model = nn.Sequential(nn.Conv2d(3, 8, kernel_size=3, stride=1, padding=1),
                             nn.MaxPool2d(2,2))

Is this output channel that is set to 8, if we can set it to anything or some predefined calculation.

Hello sir, I wanted to ask what is the exact function of Model.train() being used while training for the CNN model in this notebook.

Earlier we havent been using it. A search on Google tells me, it sets the mode of training but what does it actually mean and why did we need it here.

    def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD):
        history = []
        optimizer = opt_func(model.parameters(), lr)
        for epoch in range(epochs):
            # Training Phase 
            model.train()
            train_losses = []
            for batch in train_loader:
                loss = model.training_step(batch)
                train_losses.append(loss)
                loss.backward()
                optimizer.step()
                optimizer.zero_grad()
            # Validation phase
            result = evaluate(model, val_loader)
            result['train_loss'] = torch.stack(train_losses).mean().item()
            model.epoch_end(epoch, result)
            history.append(result)

After modifying the Cifar10Cnn Model, i tried creating my model and i keep getting this “TypeError: torch.nn.modules.activation.ReLU is not a Module subclass”. I any idea what the issue might be?

Hi, Finally able to resolve this error.
This link was helpful

What will happen when we will not used random_seed in model?

how can I generate a Confusion matrix in an image classification with CNN in Pytorch? thanks

1 Like

My problem is that my validation accuracy is increasing in CNN Model but validation loss is also increasing very rapidly , is this due to Overfitting

As long as accuracy is increasing it’s fine, you can continue with the training.

1 Like

I want to know what is the reason for this, and what is the intuition behind it.

You will get your answer here,
tensorflow - How to interpret increase in both loss and accuracy - Stack Overflow.

Also the last answer in this website is quite helpful.

Here is my blog on a quick overview of Convolutional Neural Network. Please go through it, it will be very useful and informative for you

https://bhupendraiiti.medium.com/convolutional-neural-network-in-deep-learning-c998d07a3dab

1 Like

I just published Blog, How to create a deep learning model to generate images of handwritten digits similar to those from the MNIST database using Generative Adversarial Network(GAN)

https://bhupendraiiti.medium.com/generative-adversarial-network-gan-92c614ba9e64

1 Like

These are very informative blogs. Thanks for sharing.
Tip: You can share these blogs in this thread Top Notebook Weekly Giveaway 🔥 | Week 2 | June 2021 if you haven’t already.