RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed
I get:


  RuntimeError: Assertion `cur_target >= 0 &amp;&amp; cur_target &lt; n_classes'
  failed.  at
  /opt/conda/conda-bld/pytorch_1550796191843/work/aten/src/THNN/generic/ClassNLLCriterion.c:93


When running this code:

    criterion = nn.CrossEntropyLoss()
    #Define the optimizer
    optimizer=optim.SGD(net.parameters(),lr=0.01,momentum=0.9)
    epochs=20
    for epoch in range(epochs):
        print ("epoch #", epoch)
        running_loss=0.0
        for i, data in enumerate(train_loader,0):
            inputs,labels=data
            inputs,labels= inputs.to(device),labels.to(device)
            optimizer.zero_grad()   
            #train
            output=net(inputs)
            loss=criterion(output,labels)

    print ("loss: ", loss.item())
    running_loss+=loss.item()
    loss.backward()
    optimizer.step()
    print ('Finished Training')


The exception says that one of your labels is out of bounds.
Maybe they start from 1 instead of 0? Try printing them out.
