Im trying to make this architecture
Below is my code :
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.conv1 = nn.Conv2d(3, 64, kernel_size=5, stride=1, padding=1)
self.conv2 = nn.Conv2d(64, 32, kernel_size=3, stride=1, padding=1)
self.conv3 = nn.Conv2d(32, 16, kernel_size=3, stride=1, padding=1)
self.maxPool2d = nn.MaxPool2d(kernel_size=2, stride =2)
self.flatten = nn.Flatten()
self.fc1 = nn.Linear(784, 16)
self.fc2 = nn.Linear(16, 26)
def forward(self, x):
y = self.conv1(x)
y = F.relu(y)
y = self.maxPool2d(y)
y = self.conv2(y)
y = F.relu(y)
y = self.maxPool2d(y)
y = self.conv3(y)
y = F.relu(y)
y = self.maxPool2d(y)
y = self.flatten(y)
y = self.fc1(y)
y = self.fc2(y)
return y
for epochs in range(epoch):
print("Epoch : ", epochs)
model.train() #training loop
running_loss = 0.0
running_corrects = 0
for inputs, labels in train_loader:
inputs = inputs.to(device)
labels = labels.to(device)
optimizer.zero_grad()
outputs = model(inputs)
_, preds = torch.max(outputs,1)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
running_loss += loss.item()/inputs.size(0)
running_corrects += torch.sum(preds == labels.data)/inputs.size(0)
exp_lr_scheduler.step() #schedule the learning rate for next the epoch of training
train_epoch_loss = running_loss / len(train_loader)
train_epoch_acc = running_corrects / len(train_loader)
model.eval() #validation loop
running_loss = 0.0
running_corrects = 0
for inputs, labels in val_loader:
inputs = inputs.to(device)
labels = labels.to(device)
outputs = model(inputs)
_, preds = torch.max(outputs,1)
loss = criterion(outputs, labels)
running_loss += loss.item()/inputs.size(0)
running_corrects +=torch.sum(preds == labels.data)/inputs.size(0)
epoch_loss = running_loss / len(val_loader)
epoch_acc = running_corrects.double() / len(val_loader)
print("Train: Loss: {:.4f} Acc: {:.4f}"
" Val: Loss: {:.4f}"
" Acc: {:.4f}".format(train_epoch_loss,train_epoch_acc,epoch_loss,epoch_acc))
somehow it stucks on epoch 0 and doesn’t show the result even after an hour. I used the asl alphabet dataset. Can any one help me?
here is the full code : https://drive.google.com/file/d/1zWjrj2cslnIdj252uM1DFyzddMBHib8p/view?usp=sharing