Skip to content

Instantly share code, notes, and snippets.

@cedrickchee
Created January 18, 2018 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedrickchee/e6da24a7b7e7243793e1f583661e343d to your computer and use it in GitHub Desktop.
Save cedrickchee/e6da24a7b7e7243793e1f583661e343d to your computer and use it in GitHub Desktop.
Create Kaggle Dog Breed Identification Challenge submission.csv file
# Step - Submit Predictions
# We have finished training and ready to run predictions on the test set.
log_test_preds = learn.predict(is_test=True)
# Convert log predictions to just probabilities (predictions).
test_preds = np.exp(log_test_preds)
# Create the submission file using the probabilities
# Get a list of image file names from the test data loader
im_fnames = data.test_dl.dataset.fnames
# We need to control the order of our predictions - it is not the same as in sample_submission.csv file. Order of categories is the same because it's in alphabetical order.
test_df = pd.DataFrame(test_preds)
# Here's how to get those predictions into a csv file for submitting. For more, refer to this Kaggle kernel: https://www.kaggle.com/orangutan/keras-vgg19-starter
sample_sub_csv = f'{PATH}sample_submission.csv'
df_sample_sub = pd.read_csv(sample_sub_csv, index_col='id')
# Get column names from sample_submission.csv
sub_columns = df_sample_sub.columns
# Sanity check - print first 3 rows of test preds pandas dataframe.
test_df.head(n=3)
final_df = test_df
# Assign column names from sample submission into the final submission df.
final_df.columns = sub_columns
# Get the image file names from test set
test_fnames = [i.split('.jpg')[0].split('/')[-1] for i in data.test_dl.dataset.fnames]
# Set the final submission df index column (id) values using the test set file names
final_df.index = test_fnames
final_df.index.name = 'id' # set index column name
# Save final submission dataframe to CSV file.
final_df.to_csv(PATH + 'submission_299_pre_one_more_cycle_1.csv', index=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment