Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
romeokienzler authored Mar 2, 2020
1 parent 2ee9d69 commit 0f7949f
Showing 1 changed file with 83 additions and 32 deletions.
115 changes: 83 additions & 32 deletions notebooks/tf2savedModel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using default tag: latest\n",
"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?\n",
"docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.\n",
"See 'docker run --help'.\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!docker pull tensorflow/serving\n",
"!docker run -t --rm -p 8501:8501 -v \"$(pwd)/mymodel/:/models/mymodel\" -e MODEL_NAME=mymodel tensorflow/serving"
Expand Down Expand Up @@ -257,33 +246,95 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"mymodelweb/\n",
"├── group1-shard1of3.bin\n",
"├── group1-shard2of3.bin\n",
"├── group1-shard3of3.bin\n",
"└── model.json\n",
"\n",
"0 directories, 4 files\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!tree mymodelweb/"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TensorFlow Hub"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow_hub as hub\n",
"\n",
"hub_url = \"https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1\"\n",
"embed = hub.KerasLayer(hub_url)\n",
"embeddings = embed([\"A long sentence.\", \"single-word\", \"http://example.com\"])\n",
"print(embeddings.shape, embeddings.dtype)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import tensorflow.keras as keras\n",
"from tensorflow.keras.layers import Dense\n",
"model = keras.Sequential()\n",
"model.add(Dense(23, input_shape=(None,23)))\n",
"model.add(embed)\n",
"model.add(keras.layers.Dense(16, activation='relu'))\n",
"model.add(keras.layers.Dense(1, activation='sigmoid'))\n",
"model.build()\n",
"model.summary()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model = tf.keras.Sequential([\n",
" embed,\n",
" tf.keras.layers.Dense(16, activation=\"relu\"),\n",
" tf.keras.layers.Dense(1, activation=\"sigmoid\"),\n",
"])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"model.summary()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TensorFlow Hub"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_url = \"https://tfhub.dev/google/tf2-preview/nnlm-en-dim128/1\"\n",
"hub_layer = hub.KerasLayer(model_url, output_shape=[128], input_shape=[], dtype=tf.string)\n",
"\n",
"model = keras.Sequential()\n",
"model.add(hub_layer)\n",
"model.add(...)\n",
"...\n",
"model.summary()\n"
]
}
],
"metadata": {
Expand Down

0 comments on commit 0f7949f

Please sign in to comment.