Good accuracy and loss on training vs bad accuracy on validation
I am learning pytorch and I have created binary classification algorithm. After having trained the model I have very low loss and quite good accuracy. However, on validation the accuracy is exactly 50%. I am wondering if I loaded samples incorrectly or the algorithm does not perform well.
Here you can find the plot of Training loss and accuracy.
Here is my training method:
epochs = 15
itr = 1
p_itr = 100
model.train()
total_loss = 0
loss_list = []
acc_list = []
for epoch in range(epochs):
    for samples, labels in train_loader:
        samples, labels = samples.to(device), labels.to(device)
        optimizer.zero_grad()
        output = model(samples)
        labels = labels.unsqueeze(-1)
        labels = labels.float()
        loss = criterion(output, labels)
        loss.backward()
        optimizer.step()
        total_loss += loss.item()
        scheduler.step()
    
    #if itr%p_itr == 0:
    pred = torch.round(output)
    correct = pred.eq(labels)
    acc = torch.mean(correct.float())
    print('[Epoch {}/{}] Iteration {} -&gt; Train Loss: {:.4f}, Accuracy: {:.3f}'.format(epoch+1, epochs, itr, total_loss/p_itr, acc))
    loss_list.append(total_loss/p_itr)
    acc_list.append(acc)
    total_loss = 0
        
    itr += 1

Here, I am loading data from the path:
train_list_cats = glob.glob(os.path.join(train_cats_dir,'*.jpg'))
train_list_dogs = glob.glob(os.path.join(train_dogs_dir,'*.jpg'))
train_list = train_list_cats + train_list_dogs

val_list_cats = glob.glob(os.path.join(validation_cats_dir,'*.jpg'))
val_list_dogs = glob.glob(os.path.join(validation_dogs_dir,'*.jpg'))

val_list = val_list_cats + val_list_dogs

I am not attaching the model architecture, however I can add it if required.
I think that my training method is correct, although, I am not sure about training/validation data processing.
Edit:
The network params are as follow:
optimizer = torch.optim.RMSprop(model.parameters(), lr=0.001)
criterion = nn.BCELoss()
scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[500,1000,1500], gamma=0.5)

Activation function is sigmoid.
The network architecture:
 self.layer1 = nn.Sequential(
        nn.Conv2d(3,16,kernel_size=3),
        nn.ReLU(),
        nn.MaxPool2d(2),
        nn.Dropout(p=0.2)
    )
    
    self.layer2 = nn.Sequential(
        nn.Conv2d(16,32, kernel_size=3),
        nn.ReLU(),
        nn.MaxPool2d(2),
        nn.Dropout(p=0.2)
        )
    
    self.layer3 = nn.Sequential(
        nn.Conv2d(32,64, kernel_size=3),
        nn.ReLU(),
        nn.MaxPool2d(2),
        nn.Dropout(p=0.2)
    )       
  
    self.fc1 = nn.Linear(17*17*64,512)
    self.fc2 = nn.Linear(512,1)
    self.relu = nn.ReLU()
    self.sigmoid = nn.Sigmoid()
    
    
def forward(self,x):
    out = self.layer1(x)
    out = self.layer2(out)
    out = self.layer3(out)
    out = out.view(out.size(0),-1)
    out = self.relu(self.fc1(out))
    out = self.fc2(out)
    return torch.sigmoid(out)


Going by your &quot;Training loss and accuracy&quot; plot your model is overfitting. Your train loss is near zero after 25 epochs and you continue training for 200+ epochs. This is wrong way to train a model. You should rather be doing early stopping based on the validation set. ie. Run one epoch of train and one epoch of eval and repeat. Stop when your train epoch is improving and the corresponding eval epoch is not improving.
