Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save easonlai/0575daee3bde2631bba262c32b5d8288 to your computer and use it in GitHub Desktop.
Save easonlai/0575daee3bde2631bba262c32b5d8288 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"export_path = docker\\models\\model\\1\n",
"\n",
"WARNING:tensorflow:From C:\\Users\\easlai\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\tensorflow_core\\python\\ops\\resource_variable_ops.py:1786: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n",
"Instructions for updating:\n",
"If using Keras pass *_constraint arguments to layers.\n",
"INFO:tensorflow:Assets written to: docker\\models\\model\\1\\assets\n",
"\n",
"Saved model\n"
]
}
],
"source": [
"# Fetch the Keras session and save the model\n",
"# The signature definition is defined by the input and output tensors, and stored with the default serving key\n",
"import tempfile\n",
"\n",
"MODEL_DIR = 'docker\\models\\model'\n",
"version = 1\n",
"export_path = os.path.join(MODEL_DIR, str(version))\n",
"print('export_path = {}\\n'.format(export_path))\n",
"\n",
"tf.keras.models.save_model(\n",
" model,\n",
" export_path,\n",
" overwrite=True,\n",
" include_optimizer=True,\n",
" save_format=None,\n",
" signatures=None,\n",
" options=None\n",
")\n",
"\n",
"print('\\nSaved model')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'docker\\\\zip_models\\\\1.zip'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Packaging model file as zip for later on DevOps integration use\n",
"import shutil\n",
"model_version = str(version)\n",
"shutil.make_archive(model_version, 'zip', 'docker\\models\\model')\n",
"model_version_source = str(version) + '.zip'\n",
"model_version_dest = \"docker\\\\zip_models\\\\\" + model_version + '.zip'\n",
"shutil.move(model_version_source, model_version_dest)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment