# \[resolved\]Loss not decreasing

**URL:** <https://discuss.pytorch.org/t/resolved-loss-not-decreasing/8413>\
**Category:** Uncategorized\
**Created:** [October 7, 2017, 8:08pm UTC](https://discuss.pytorch.org/t/resolved-loss-not-decreasing/8413 "2017-10-07T20:08:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wuhoo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/w/f1d935/32.png) [@wuhoo](https://discuss.pytorch.org/u/wuhoo)\
**Post date:** [October 7, 2017, 8:08pm UTC](https://discuss.pytorch.org/t/resolved-loss-not-decreasing/8413/1 "2017-10-07T20:08:14Z")

</div>

Hi, I want to know why the loss is not decreasing? Bascially it’s always the initial loss. Thanks in advance!  
optimizer.zero\_grad()

```
                    # forward
                    output = net(imgdata)
            
                    _, preds = torch.max(output.data,1)
                 
                    for i in range(output.size()[1]):
                        loss = criterion(output[:,:,:,i],labels.type(torch.LongTensor)[:,:,i])
                    print('Loss per batch ', loss.data[0])

                    if phase == 'train':
                        loss.backward()
                        optimizer.step()
                    
                    next = batch_indices
                   
                    running_loss += loss.data[0]
```

---

<div class="post-metadata">

**Author:** ![alexbellgrande](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alexbellgrande/32/163_2.png) [@alexbellgrande](https://discuss.pytorch.org/u/alexbellgrande)\
**Post date:** [October 7, 2017, 11:14pm UTC](https://discuss.pytorch.org/t/resolved-loss-not-decreasing/8413/2 "2017-10-07T23:14:28Z")

</div>

I’m not sure if this is going to solve your entire problem but one error is that you set the variable i with the 1st dimension of output but then use it to iterate over the third dimension.

you should either do:

```auto
for i in range(output.size()[1])
    loss = criterion(output[:, i], labels.type(torch.Longtensor)[i]

```

or

```auto
for i in range(output.size()[3])
    loss = criterion(output[:, :, :, i], labels.type(torch.Longtensor)[:, : i]

```

---

<div class="post-metadata">

**Author:** ![wuhoo](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/w/f1d935/32.png) [@wuhoo](https://discuss.pytorch.org/u/wuhoo)\
**Post date:** [October 8, 2017, 2:34am UTC](https://discuss.pytorch.org/t/resolved-loss-not-decreasing/8413/4 "2017-10-08T02:34:41Z")

</div>

Your are right. Thanks for pointing that out!
