Lecture 4: Image Classification with Convolutional Neural Networks

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

Lecture Date and Time: December 12, 2020,
English: 9 PM IST/8.30 AM PST | Add to calendar (Google)
Hindi: 11 AM IST | Add to calendar (Google)

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 on this thread to ask questions during and after the lecture. Before asking, scroll through the thread and check if your question (or a similar one) is already present. If yes, just like it. During the lecture, we’ll answer 8-10 questions with the most likes. The rest will be answered on the forum. 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