Skip to content

Instantly share code, notes, and snippets.

@frenzy2106
Created March 17, 2020 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frenzy2106/8c7276b463a169b46690f7da4dfab802 to your computer and use it in GitHub Desktop.
Save frenzy2106/8c7276b463a169b46690f7da4dfab802 to your computer and use it in GitHub Desktop.
# unzip the test file to read images
!unzip /content/drive/My\ Drive/test_ScVgIM0.zip
# Read test file names
test = pd.read_csv('test.csv')
test_copy = test.copy()
# Read test images and preprocess
test_image = []
for i in tqdm(range(test.shape[0])):
img = image.load_img('test/'+test['id'][i].astype('str')+'.png', target_size=(28,28,1), grayscale=True)
img = image.img_to_array(img)
img = img/255
test_image.append(img)
test = np.array(test_image)
# Make Predictions using the trained model
prediction = model.predict_classes(test)
# Write submission file to score
submission['id'] = test_copy['id']
submission['label'] = prediction
submission.to_csv('submission_cnn.csv', header=True, index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment