Lesson 1 discussion

@Vijay

Saving predictions to a CSV

Approach 1: import numpy as np

isdog = preds[:,1]
filenames = batches.filenames
ids = np.array([int(f[8:f.find('.')]) for f in filenames])
subm = np.stack([ids,isdog], axis=1)
submission_file_name = 'submission1.csv'
np.savetxt(submission_file_name, subm, fmt='%d,%.5f', header='id,label', comments='')

where batches and preds are the output of vgg.test.

Submission properties: Probabilities as answers; two classes

See the end of this notebook: https://github.com/fastai/courses/blob/master/deeplearning1/nbs/dogs_cats_redux.ipynb

Approach 2: import csv

filenames = test_batches.filenames
ids = [filename.split('/')[1].split('.')[0] + ".ppm" for filename in filenames]
classes = [np.argmax(prob) for prob in probs]
pairs = zip(ids, classes)
with open(results_path+"submission--lesson-1--vgg16--12-epochs--peak.csv", "w") as f:
    writer = csv.writer(f, delimiter=";")
    writer.writerows(pairs)

where test_batches and probs are the output of vgg.test.

Submission properties: Labels as answers; 43 classes

See the end of this notebook: https://github.com/MatthewKleinsmith/fast-ai-MOOC/blob/master/german-traffic-signs.ipynb

9 Likes