diff --git a/object_detection.ipynb b/object_detection.ipynb index 702611c..b10922d 100644 --- a/object_detection.ipynb +++ b/object_detection.ipynb @@ -1,19 +1,4 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "Copy of Copy of object-detection.ipynb", - "provenance": [], - "collapsed_sections": [], - "toc_visible": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "accelerator": "GPU" - }, "cells": [ { "cell_type": "markdown", @@ -26,9 +11,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "GmloKE6Qx8Lu" }, + "outputs": [], "source": [ "credentials = {\n", " \"bucket\": \"BUCKET\",\n", @@ -36,15 +23,15 @@ " \"secret_access_key\": \"SECRET_ACCESS_KEY\",\n", " \"endpoint_url\": \"ENDPOINT_URL\"\n", "}" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "hVPzEKoLuEHy" }, + "outputs": [], "source": [ "NUM_TRAIN_STEPS = 500\n", "MODEL_TYPE = 'ssd_mobilenet_v1_quantized_300x300_coco14_sync_2018_07_18'\n", @@ -62,9 +49,7 @@ "LABEL_MAP_PATH = os.path.join(DATA_PATH, 'label_map.pbtxt')\n", "TRAIN_RECORD_PATH = os.path.join(DATA_PATH, 'train.record')\n", "VAL_RECORD_PATH = os.path.join(DATA_PATH, 'val.record')" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -89,9 +74,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "o33_jgwGm3NV" }, + "outputs": [], "source": [ "%tensorflow_version 1.x\n", "import os\n", @@ -114,9 +101,7 @@ "\n", "pwd = os.getcwd()\n", "os.environ['PYTHONPATH'] += f':{pwd}:{pwd}/slim'" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -130,14 +115,14 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "iM8sOHwL64Rp" }, + "outputs": [], "source": [ "!python object_detection/builders/model_builder_tf1_test.py" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -151,15 +136,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "jydTH9gYQ3y7" }, + "outputs": [], "source": [ "import cloud_annotations as ca\n", "ca.mount(CLOUD_ANNOTATIONS_MOUNT, credentials)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -191,9 +176,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "nJsKCG3UdDsn" }, + "outputs": [], "source": [ "import os\n", "import json\n", @@ -213,9 +200,7 @@ " f.write(\"\\tname: '{}'\\n\".format(label))\n", " f.write('\\tid: {}\\n'.format(idx + 1)) # indexes must start at 1\n", " f.write('}\\n')" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -247,17 +232,21 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "cAkOvP-gZR1x" }, + "outputs": [], "source": [ "import os\n", "import io\n", "import json\n", "import random\n", "\n", - "import PIL.Image\n", "import tensorflow as tf\n", + "import PIL.Image\n", + "from PIL import JpegImagePlugin\n", + "JpegImagePlugin._getmp = lambda x: None\n", "\n", "from object_detection.utils import dataset_util\n", "from object_detection.utils import label_map_util\n", @@ -328,8 +317,8 @@ " if tf_example:\n", " # Write the TFExample to the TFRecord.\n", " writer.write(tf_example.SerializeToString())\n", - " except ValueError:\n", - " print('Invalid example, ignoring.')\n", + " except ValueError as e:\n", + " print(e)\n", " pass\n", " except IOError:\n", " print(\"Can't read example, ignoring.\")\n", @@ -349,9 +338,7 @@ "\n", " create_tf_record(train_examples, annotations, label_map, CLOUD_ANNOTATIONS_MOUNT, TRAIN_RECORD_PATH)\n", " create_tf_record(val_examples, annotations, label_map, CLOUD_ANNOTATIONS_MOUNT, VAL_RECORD_PATH)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -375,9 +362,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "oHD1Jm0v7jfz" }, + "outputs": [], "source": [ "import os\n", "import tarfile\n", @@ -401,9 +390,7 @@ " tar.extract(member, path=CHECKPOINT_PATH)\n", "\n", " os.remove(tmp)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -417,9 +404,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "C8CVExv6HsJS" }, + "outputs": [], "source": [ "import re\n", "\n", @@ -447,9 +436,7 @@ "configs = config_util.merge_external_params_with_configs(configs, kwargs_dict=override_dict)\n", "pipeline_config = config_util.create_pipeline_proto_from_configs(configs)\n", "config_util.save_pipeline_config(pipeline_config, DATA_PATH)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -467,9 +454,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "Wv5h2bwBVO0V" }, + "outputs": [], "source": [ "!rm -rf $OUTPUT_PATH\n", "!python -m object_detection.model_main \\\n", @@ -477,9 +466,7 @@ " --model_dir=$OUTPUT_PATH \\\n", " --num_train_steps=$NUM_TRAIN_STEPS \\\n", " --num_eval_steps=100" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -495,9 +482,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "BZgP_FZUoE0d" }, + "outputs": [], "source": [ "import os\n", "import re\n", @@ -513,9 +502,7 @@ " --pipeline_config_path=$DATA_PATH/pipeline.config \\\n", " --trained_checkpoint_prefix=$TRAINED_CHECKPOINT_PREFIX \\\n", " --output_directory=$EXPORTED_PATH" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -531,9 +518,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "HWHvlnyjmCIN" }, + "outputs": [], "source": [ "from IPython.display import display, Javascript, Image\n", "from google.colab.output import eval_js\n", @@ -642,9 +631,7 @@ " line_thickness=8)\n", " plt.figure(figsize=(12, 8))\n", " plt.imshow(image_np)" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -660,9 +647,11 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "A-f5lfcnp01e" }, + "outputs": [], "source": [ "!tensorflowjs_converter \\\n", " --input_format=tf_frozen_model \\\n", @@ -684,9 +673,7 @@ " json.dump(label_array, f)\n", "\n", "!cd /content/model_web && zip -r /content/model_web.zip *" - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -702,15 +689,15 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { "id": "FL_miSj2r1yt" }, + "outputs": [], "source": [ "from google.colab import files\n", "files.download('/content/model_web.zip') " - ], - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", @@ -722,5 +709,20 @@ "Use the `model_web` folder generated here, with this [project](https://github.com/cloud-annotations/object-detection-react) to create a real-time webcam object detection app." ] } - ] + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [], + "name": "Copy of Copy of object-detection.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 }