Kaggle datasets

Hi, everyone
I have used transfer learning for the 3 classes and trained the model successfully.
it is a kaggle dataset project now I need the label of the classes for the kaggle to save them in the CSV files and upload in the kaggle. But when I run this code “learn.predict(‘gdrive/My Drive/dlai3-phase3/VALIDATE/VALIDATE/VAL_SET3 (1).png’)”, it give the result like this (’(‘THORAXDISEASE’, tensor(2), tensor([5.0011e-05, 2.0994e-05, 9.9993e-01])).
Can anyone please help me to print the label of the datasets in the CSV files?

Hi @vakili786

Most kaggle competitions have a submission file called sample_submission.csv with an ID column and a column for your predictions. Do you have such file?

You could loop through all pictures, get the prediction for each and append the first item of the output from learn.predict(), i.e. the predicted class name, to a list of results like this:

res = []
for i in range(len(test_paths):
    out = learn.predict(test_paths[i])

Then you can load sample_submission.csv using pandas, replace the column dedicated to predictions with the list of your results and save the dataframe with your predictions as a csv file.

Note that it’s important that the items in test_paths have the exact same order as the IDs in the submission file.

1 Like

Thank you so much, I truly appreciate your help.
yes, I have that file, screenshot of the file attached belowsubmission.

Hi dear
it gives error FileNotFoundError: [Errno 2] No such file or directory: ‘g’.
also, the code attached below.

could you please help to solve this error?

Test paths should be a list of all image paths that you want to run inference on.

Something like this:

test_paths = [‘gdrive/My Drive/dlai3-phase3/VALIDATE/VALIDATE/VAL_SET3 (1).png’, ‘gdrive/My Drive/dlai3-phase3/VALIDATE/VALIDATE/VAL_SET3 (2).png’, ‘gdrive/My Drive/dlai3-phase3/VALIDATE/VALIDATE/VAL_SET3 (3).png’…]

1 Like

Ok thank you so much for contribution!