The kernel for ProjectName.ipynb appears to have died. It will restart automatically

25 Views Asked by At

I am trying to to build my first Neural Netwrok using the help of this code: https://github.com/nakasho5/Deep-Learning-Nanodegree/blob/main/Project1_Developing%20a%20Handwritten%20Digits%20Classifier%20with%20PyTorch/MNIST_Handwritten_Digits-STARTER_MAC.ipynb

I am facing a problem that unables me to show the picutres of the datasets. whenever I call the function show5(loader), I get an error that kills the Jupyter notebook kernel:

enter image description here

I have tried many times to install and unistall matplotlib using pip and conda for my environment.

## Importing the needed imports

import numpy as np
import matplotlib.pyplot as plt

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

from torchvision import datasets
from torchvision.transforms import ToTensor
from torch.utils.data import DataLoader
#Loading The Training Dataset and Defining it's Dataloader
training_data = datasets.MNIST(
    root = "data",
    train = True,
    download = True,
    transform = ToTensor()
)

training_loader = DataLoader(
    training_data,
    batch_size = 100,
    shuffle = True
)


#Loading The Testing Dataset and Defining it's Dataloader

testing_data = datasets.MNIST(
    root = "data",
    train = False,
    download = True,
    transform = ToTensor()
)

testing_loader = DataLoader(
    testing_data,
    batch_size = 100,
    shuffle = True
)
## This cell contains a function for showing 5 images from a dataloader – DO NOT CHANGE THE CONTENTS! ##
def show5(img_loader):
    dataiter = iter(img_loader)
    
    batch = next(dataiter)
    labels = batch[1][0:5]
    images = batch[0][0:5]
    for i in range(5):
        print(int(labels[i].detach()))
    
        image = images[i].numpy()
        plt.imshow(image.T.squeeze().T)
        plt.show()
show5(training_loader)

How to resolve this?

0

There are 0 best solutions below