Loss is between 4 and 3'5 and never close to 0

Leon_Lopez: <p>Hello, I am new in pytorch and machine learning.</p>
<p>Training and validatin my dataset, I obtain loss between 4 and 3.5 per epoch.<br>
I am using Cross Entropy Loss function.</p>
<p>I am calculating the mean of the epochs in the next way:</p>
<pre><code class="lang-auto">train.model()
 for batch, (data, target) in enumerate(train_loader, 1):
            optimizer.zero_grad()
            if CUDA:
                data = data.cuda()
                target = target.cuda()
            output = model(data)
            target = torch.argmax(target,1)
            loss = criterion(output, target)
            loss.backward()
            optimizer.step()
            train_losses.append(loss.item())
            pred = torch.max(output, 1)[1]
            correct_train += pred.eq(target).sum()

        model.eval()
        for data, target in val_loader:
            if CUDA:
                data = data.cuda()
                target = target.cuda()
            output = model(data)
            target = torch.argmax(target,1)
            loss = criterion(output, target)
            valid_losses.append(loss.item())
            pred = torch.max(output, 1)[1]
            correct_val += pred.eq(target).sum()

train_loss = np.average(train_losses)
valid_loss = np.average(valid_losses)
</code></pre>
<p>Most of examples I had seen have losses closely to 0.</p>
<p>I am not sure if I my model is working correctly.</p>
<p>Maybe I should do:</p>
<pre><code class="lang-auto">train_loss = train_losses/len(trainLoader.dataset)
valid_loss = valid_loss/len(valLoader.dataset)
</code></pre>
<p>I attach an image of a train with 1000 epochs but I stopped in 505 because it was improving very slow.</p>
<p>I think the difference with validation loss and training loss is because there is dropout in the training.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/9/90e9d0e730330f6988e6195e57afe492962512c6.png" data-download-href="https://discuss.pytorch.org/uploads/default/90e9d0e730330f6988e6195e57afe492962512c6" title="imagen"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/9/90e9d0e730330f6988e6195e57afe492962512c6_2_597x500.png" alt="imagen" data-base62-sha1="kFXHFe6LHyUoDu7Jx5OBQE7TDgi" width="597" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/9/90e9d0e730330f6988e6195e57afe492962512c6_2_597x500.png, https://discuss.pytorch.org/uploads/default/original/2X/9/90e9d0e730330f6988e6195e57afe492962512c6.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/9/90e9d0e730330f6988e6195e57afe492962512c6.png 2x" data-dominant-color="FBFAFA"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">imagen</span><span class="informations">712×596 34.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>If you have doubt about your training, I would suggest to scale down the problem and e.g. use only a small subset of your data (e.g. 10 samples) and try to overfit your model.<br>
If the loss cannot converge towards zero, your code might have some bugs or the model is just not suitable for your use case.</p>