Created
October 7, 2019 13:07
-
-
Save aymericdelab/47b5952ac1db148a2f7658ce92eef9a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"## first downlaod the output of your model from azure blob storage\n", | |
"ds = ws.get_default_datastore()\n", | |
"\n", | |
"ds.download(target_path='outputs',\n", | |
" prefix='founder-classifier/outputs/model',\n", | |
" show_progress=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"INFO:tensorflow:Restoring parameters from outputs/founder-classifier/outputs/model/1570442423\\variables\\variables\n" | |
] | |
} | |
], | |
"source": [ | |
"## restore your tf.estimator\n", | |
"\n", | |
"from tensorflow.contrib import predictor\n", | |
"\n", | |
"saved_model_location='outputs/founder-classifier/outputs/model/1570442423'\n", | |
"\n", | |
"loaded_model = predictor.from_saved_model(saved_model_location)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The accuracy on the test set is: 0.8847352024922118\n" | |
] | |
} | |
], | |
"source": [ | |
"## load your test set\n", | |
"import json\n", | |
"import numpy as np\n", | |
"\n", | |
"with open('./data/test.json', 'rb') as f:\n", | |
" test_data=json.load(f)\n", | |
"\n", | |
"features=np.reshape(test_data['images'], (-1,28,28,1))\n", | |
"\n", | |
"## make predictions\n", | |
"predictions = loaded_model({'x': features})['classes']\n", | |
"\n", | |
"true_labels=test_data['labels']\n", | |
"\n", | |
"## compute the accuracy\n", | |
"count=0\n", | |
"for i in range(len(predictions)):\n", | |
" if predictions[i]==true_labels[i]:\n", | |
" count+=1\n", | |
"accuracy=count/len(predictions)\n", | |
"print('The accuracy on the test set is: ', accuracy)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "conda_tensorflow_p36", | |
"language": "python", | |
"name": "conda_tensorflow_p36" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment