Muhammad-MujtabaSaeed / Caltech-Birds-Classification

This repo includes code (written in Python) for Caltech-UCSD Birds-200-2011 dataset classification. I have used PyTorch Library for CNN's. You can download the dataset here http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz
29 stars 11 forks source link

Unable to display epoch accuracy. #1

Closed ghost closed 5 years ago

ghost commented 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.
capture

Muhammad-MujtabaSaeed commented 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. capture

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))

ghost commented 5 years ago

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 ?

Muhammad-MujtabaSaeed commented 5 years ago

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.