diff --git a/demo.ipynb b/demo.ipynb index 143503a31b0bd1843a95e7c4f3d2bf95696ab09b..b72047d4cbbb30c9b400d8fba9917e6aa51639e0 100644 --- a/demo.ipynb +++ b/demo.ipynb @@ -45,10 +45,11 @@ "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", - "# Path to trained weights file\n", - "# Download this file and place in the root of your \n", - "# project (See README file for details)\n", + "# Local path to trained weights file\n", "COCO_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_coco.h5\")\n", + "# Download COCO trained weights from Releases if needed\n", + "if not os.path.exists(COCO_MODEL_PATH):\n", + " utils.download_trained_weights(COCO_MODEL_PATH)\n", "\n", "# Directory of images to run detection on\n", "IMAGE_DIR = os.path.join(ROOT_DIR, \"images\")" @@ -144,6 +145,7 @@ "cell_type": "code", "execution_count": 3, "metadata": { + "collapsed": true, "scrolled": false }, "outputs": [], @@ -282,7 +284,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.2" } }, "nbformat": 4, diff --git a/inspect_model.ipynb b/inspect_model.ipynb index 67ecb6f981e0aab84d19a5de8bc9c01672e2e436..cccefe8c45bbecc2c3034dac29092b25572eb5e8 100644 --- a/inspect_model.ipynb +++ b/inspect_model.ipynb @@ -49,10 +49,11 @@ "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", - "# Path to trained weights file\n", - "# Download this file and place in the root of your \n", - "# project (See README file for details)\n", + "# Local path to trained weights file\n", "COCO_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_coco.h5\")\n", + "# Download COCO trained weights from Releases if needed\n", + "if not os.path.exists(COCO_MODEL_PATH):\n", + " utils.download_trained_weights(COCO_MODEL_PATH)\n", "\n", "# Path to Shapes trained weights\n", "SHAPES_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_shapes.h5\")" @@ -1377,7 +1378,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.2" } }, "nbformat": 4, diff --git a/inspect_weights.ipynb b/inspect_weights.ipynb index 3519397797766ae0477ebc7f96c3d78c9ad06a78..912fae84c81e8e7f2afa10f46d0ba1b90f0e261e 100644 --- a/inspect_weights.ipynb +++ b/inspect_weights.ipynb @@ -44,8 +44,11 @@ "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", - "# Path to COCO trained weights\n", + "# Local path to trained weights file\n", "COCO_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_coco.h5\")\n", + "# Download COCO trained weights from Releases if needed\n", + "if not os.path.exists(COCO_MODEL_PATH):\n", + " utils.download_trained_weights(COCO_MODEL_PATH)\n", "\n", "# Path to Shapes trained weights\n", "SHAPES_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_shapes.h5\")" @@ -266,7 +269,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.2" } }, "nbformat": 4, diff --git a/train_shapes.ipynb b/train_shapes.ipynb index 25ff3c7ea46a4902939b82400e80448c5ab563e5..666b4db3edfccad641f4708d0ec23e95930f5ea5 100644 --- a/train_shapes.ipynb +++ b/train_shapes.ipynb @@ -51,8 +51,11 @@ "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", - "# Path to COCO trained weights\n", - "COCO_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_coco.h5\")" + "# Local path to trained weights file\n", + "COCO_MODEL_PATH = os.path.join(ROOT_DIR, \"mask_rcnn_coco.h5\")\n", + "# Download COCO trained weights from Releases if needed\n", + "if not os.path.exists(COCO_MODEL_PATH):\n", + " utils.download_trained_weights(COCO_MODEL_PATH)" ] }, { @@ -1024,7 +1027,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.2" } }, "nbformat": 4, diff --git a/utils.py b/utils.py index c93b2861cbff84f89575546bcfea07607d6e20aa..13d13b743d515275e8b66672f084e2b7d6a1af81 100644 --- a/utils.py +++ b/utils.py @@ -16,6 +16,11 @@ import tensorflow as tf import scipy.misc import skimage.color import skimage.io +import urllib.request +import shutil + +# URL from which to download the latest COCO trained weights +COCO_MODEL_URL = "https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5" ############################################################ @@ -688,3 +693,16 @@ def batch_slice(inputs, graph_fn, batch_size, names=None): result = result[0] return result + + +def download_trained_weights(coco_model_path, verbose=1): + """Download COCO trained weights from Releases. + + coco_model_path: local path of COCO trained weights + """ + if verbose > 0: + print("Downloading pretrained model to " + coco_model_path + " ...") + with urllib.request.urlopen(COCO_MODEL_URL) as resp, open(coco_model_path, 'wb') as out: + shutil.copyfileobj(resp, out) + if verbose > 0: + print("... done downloading pretrained model!")