Hello,
I want to train a CNN model with the GTSRB dataset, I made the model (wth 43 classes and 3 channels)
But I’m getting an error when I try to pass an image
Here’s my network
class LeNet(Module):
def __init__(self, numChannels, classes):
# call the parent constructor
super(LeNet, self).__init__()
# initialize first set of CONV => RELU => POOL layers
self.conv1 = Conv2d(in_channels=numChannels, out_channels=20,
kernel_size=(5, 5))
self.relu1 = ReLU()
self.maxpool1 = MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
# initialize second set of CONV => RELU => POOL layers
self.conv2 = Conv2d(in_channels=20, out_channels=50,
kernel_size=(5, 5))
self.relu2 = ReLU()
self.maxpool2 = MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
# initialize first (and only) set of FC => RELU layers
self.fc1 = Linear(in_features=4320, out_features=3774)
self.relu3 = ReLU()
# initialize our softmax classifier
self.fc2 = Linear(in_features=3774, out_features=classes)
self.logSoftmax = LogSoftmax(dim=1)
And here’s my training loop, the error appears at “pred = model(x)”
for e in range(0, EPOCHS):
# set the model in training mode
model.train()
# initialize the total training and validation loss
totalTrainLoss = 0
totalValLoss = 0
# initialize the number of correct predictions in the training
# and validation step
trainCorrect = 0
valCorrect = 0
# loop over the training set
for (x, y) in trainDataLoader:
# send the input to the device
(x, y) = (x.to(device), y.to(device))
# perform a forward pass and calculate the training loss
pred = model(x)
loss = lossFn(pred, y)
# zero out the gradients, perform the backpropagation step,
# and update the weights
opt.zero_grad()
loss.backward()
opt.step()
# add the loss to the total training loss so far and
# calculate the number of correct predictions
totalTrainLoss += loss
trainCorrect += (pred.argmax(1) == y).type(
torch.float).sum().item()
The whole project is in this github repository (the show5 method is just for testing, added later on):