|
82 | 82 | "cell_type": "code",
|
83 | 83 | "execution_count": null,
|
84 | 84 | "metadata": {
|
85 |
| - "id": "Kw7YV8nN0gEb" |
| 85 | + "id": "Kw7YV8nN0gEb", |
| 86 | + "outputId": "7eed43ea-d108-4aa0-90b9-f52e7d7d8eab" |
86 | 87 | },
|
87 | 88 | "outputs": [
|
88 | 89 | {
|
|
110 | 111 | "cell_type": "code",
|
111 | 112 | "execution_count": null,
|
112 | 113 | "metadata": {
|
113 |
| - "id": "kA1D8jB3TviQ" |
| 114 | + "id": "kA1D8jB3TviQ", |
| 115 | + "outputId": "27c3a25f-ee92-47a1-edab-5e087e749d14" |
114 | 116 | },
|
115 | 117 | "outputs": [
|
116 | 118 | {
|
|
136 | 138 | },
|
137 | 139 | "outputs": [],
|
138 | 140 | "source": [
|
139 |
| - "import sys" |
| 141 | + "import sys\n", |
| 142 | + "import os" |
140 | 143 | ]
|
141 | 144 | },
|
142 | 145 | {
|
|
307 | 310 | " # Freeze the pretrained weights\n",
|
308 | 311 | " model.trainable = False\n",
|
309 | 312 | "\n",
|
310 |
| - " # We unfreeze the top 20 layers while leaving BatchNorm layers frozen\n", |
| 313 | + " # Unfreeze the top 20 layers while leaving BatchNorm layers frozen\n", |
311 | 314 | " for layer in model.layers[-20:]:\n",
|
312 | 315 | " if not isinstance(layer, layers.BatchNormalization):\n",
|
313 | 316 | " layer.trainable = True\n",
|
314 | 317 | "\n",
|
315 |
| - " # Rebuild top\n", |
| 318 | + " # Rebuild non-frozen top layers of NASNetMobile, which was initialized with include_top=False\n", |
316 | 319 | " x = layers.GlobalAveragePooling2D(name=\"avg_pool\")(model.output)\n",
|
317 | 320 | " x = layers.BatchNormalization()(x)\n",
|
318 | 321 | "\n",
|
|
341 | 344 | "source": [
|
342 | 345 | "model = build_model(NUM_CLASSES, INPUT_IMG_SIZE)\n",
|
343 | 346 | "\n",
|
| 347 | + "# Set up job on TensorFlow Cloud to train for 100 epochs on all the data\n", |
344 | 348 | "if tfc.remote():\n",
|
345 | 349 | " # Configure Tensorboard logs\n",
|
346 | 350 | " callbacks=[\n",
|
|
359 | 363 | " model.save(SAVED_MODEL_DIR)\n",
|
360 | 364 | "\n",
|
361 | 365 | "else:\n",
|
362 |
| - " # Run the training for 1 epoch and a small subset of the data to validate setup\n", |
| 366 | + " # Run the training locally for 1 epoch and a small subset of the data to validate setup\n", |
363 | 367 | " model.fit(x=x_train[:100], y=y_train[:100], validation_split=0.2, epochs=1)"
|
364 | 368 | ]
|
365 | 369 | },
|
|
382 | 386 | },
|
383 | 387 | "outputs": [],
|
384 | 388 | "source": [
|
385 |
| - "# If you are using a custom image you can install modules via requirements\n", |
386 |
| - "# txt file.\n", |
| 389 | + "# You can install custom modules for your Docker images via requirements txt file.\n", |
387 | 390 | "with open('requirements.txt','w') as f:\n",
|
388 | 391 | " f.write('tensorflow-cloud\\n')\n",
|
389 | 392 | "\n",
|
|
465 | 468 | "cIG5d4Kvls6m"
|
466 | 469 | ],
|
467 | 470 | "name": "distributed_training_nasnet_with_tensorflow_cloud.ipynb",
|
| 471 | + "provenance": [], |
468 | 472 | "toc_visible": true
|
469 | 473 | },
|
470 | 474 | "kernelspec": {
|
|
0 commit comments