I’m trying to train a dataset with AlexNet model. The task is multiclass classification (15 classes). I am wondering why I am getting very low accuracy.
I tried different learning rate but has not been improved.
Here is the snippet for the training.
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(model.parameters(), lr=1e-3, momentum=0.9)  

def train_valid_model():
    
    num_epochs=5
                          
    for epoch in range(num_epochs):  
        print('Epoch {}/{}'.format(epoch, num_epochs - 1))
               
        for phase in ['train', 'valid', 'test']:
            if phase == 'train':
                
                model.train()  
            else:
                model.eval()   
        
            train_loss = 0.0
            total_train = 0
            correct_train = 0

            for t_image, target, image_path in dataLoaders[phase]:
                                
                t_image = t_image.to(device)
                target = target.to(device)

                optimizer.zero_grad()
                
                with torch.set_grad_enabled(phase == 'train'):
                    outputs = model(t_image) 
                    outputs = F.softmax(outputs, dim=1)
                     
                    loss = criterion(outputs,target)         
                    if phase == 'train':
                        loss.backward() 
                        optimizer.step()                           
            
                _, predicted = torch.max(outputs.data, 1)
                train_loss += loss.item()* t_image.size(0)
                correct_train += (predicted == target).sum().item()
                
            epoch_loss = train_loss / len(dataLoaders[phase].dataset)
            epoch_acc = 100 * correct_train / len(dataLoaders[phase].dataset) 
                                             
            print('{} Loss: {:.4f} {} Acc: {:.4f}'.format(phase, epoch_loss, phase, epoch_acc))

Epoch 0/4
train Loss: 2.7026 train Acc: 17.2509
valid Loss: 2.6936 valid Acc: 28.7632
test Loss: 2.6936 test Acc: 28.7632

Epoch 1/4
train Loss: 2.6425 train Acc: 17.8019
valid Loss: 2.6357 valid Acc: 28.7632
test Loss: 2.6355 test Acc: 28.7632