Closed ghost closed 5 years ago
Initially, I was unable to run the code as there was an error in function train_model. I googled the error message and found a solution.
running_loss=loss.data[0] to
running_loss=loss.item()
but after making this change I am receiving this type of result.
This issue is due to library upgrades, This code was written with previous build of PyTorch and in latest builds they have used loss.item() , not loss.data[0], so thats why it gives error. Anyhow, here is your solution. try this for calculating loss and correcct predictions. running_loss += loss.item() * inputs.size(0) running_corrects += torch.sum(preds == labels.data)
This for accuracy epoch_loss = running_loss / dataset_sizes[phase] epoch_acc = running_corrects.double() / dataset_sizes[phase]
print('{} Loss: {:.4f} Acc: {:.4f}'.format( phase, epoch_loss, epoch_acc))
Hey, thank you for replying, I made the necessary changes but my accuracy doesn't increase beyond 31%. I wonder that is happening. While in your training I observed that the accuracy reached was 77%. For how many epochs did you train ?
Oh, that's strange. I don't remember exactly the number of epochs but i think that was more than 100 to around 150. Also I have used the pre-trained ResNet-18 model, that also is helpful in getting good accuracy.
Initially, I was unable to run the code as there was an error in function train_model. I googled the error message and found a solution.
but after making this change I am receiving this type of result.