From 24f6d0745a9b8cb403cb904b46b7d6a3784e7e04 Mon Sep 17 00:00:00 2001 From: Waleed Abdulla Date: Fri, 6 Apr 2018 15:36:17 -0700 Subject: [PATCH] Fix ROOT_DIR and other misc updates. - Update ROOT_DIR depending on path of file - Remove unneeded __init__.py files - Remove setting matplotlib backend --- mrcnn/model.py | 5 +++-- mrcnn/parallel_model.py | 4 ++-- mrcnn/visualize.py | 14 ++++++-------- samples/__init__.py | 0 samples/balloon/__init__.py | 0 samples/balloon/balloon.py | 7 ++----- samples/balloon/inspect_balloon_data.ipynb | 7 ++----- samples/balloon/inspect_balloon_model.ipynb | 7 ++----- samples/coco/__init__.py | 0 samples/coco/coco.py | 9 ++++++--- samples/coco/inspect_data.ipynb | 9 ++++++--- samples/coco/inspect_model.ipynb | 8 +++++--- samples/coco/inspect_weights.ipynb | 10 ++++++---- samples/demo.ipynb | 14 +++++++++----- samples/shapes/__init__.py | 0 samples/shapes/shapes.py | 7 +++++++ samples/shapes/train_shapes.ipynb | 8 +++++--- 17 files changed, 61 insertions(+), 48 deletions(-) delete mode 100644 samples/__init__.py delete mode 100644 samples/balloon/__init__.py delete mode 100644 samples/coco/__init__.py delete mode 100644 samples/shapes/__init__.py diff --git a/mrcnn/model.py b/mrcnn/model.py index 67e5b80ae4..0e50ed6758 100644 --- a/mrcnn/model.py +++ b/mrcnn/model.py @@ -11,6 +11,7 @@ import random import datetime import re +import math import logging from collections import OrderedDict import multiprocessing @@ -1980,7 +1981,7 @@ def build(self, mode, config): mrcnn_class_logits, mrcnn_class, mrcnn_bbox, mrcnn_mask, rpn_rois, output_rois, rpn_class_loss, rpn_bbox_loss, class_loss, bbox_loss, mask_loss] - model = KM.Model(inputs, outputs, name='mrcnn') + model = KM.Model(inputs, outputs, name='mask_rcnn') else: # Network Heads # Proposal classifier and BBox regressor heads @@ -2006,7 +2007,7 @@ def build(self, mode, config): model = KM.Model([input_image, input_image_meta], [detections, mrcnn_class, mrcnn_bbox, mrcnn_mask, rpn_rois, rpn_class, rpn_bbox], - name='mrcnn') + name='mask_rcnn') # Add multi-GPU support. if config.GPU_COUNT > 1: diff --git a/mrcnn/parallel_model.py b/mrcnn/parallel_model.py index 8a030983d1..26e997d0c2 100644 --- a/mrcnn/parallel_model.py +++ b/mrcnn/parallel_model.py @@ -118,10 +118,10 @@ def add_dim(tensor): GPU_COUNT = 2 # Root directory of the project - ROOT_DIR = os.getcwd() + ROOT_DIR = os.path.abspath("../") # Directory to save logs and trained model - MODEL_DIR = os.path.join(ROOT_DIR, "logs/parallel") + MODEL_DIR = os.path.join(ROOT_DIR, "logs") def build_model(x_train, num_classes): # Reset default graph. Keras leaves old ops in the graph, diff --git a/mrcnn/visualize.py b/mrcnn/visualize.py index 2451b3c632..9808512fce 100644 --- a/mrcnn/visualize.py +++ b/mrcnn/visualize.py @@ -8,19 +8,12 @@ """ import os +import sys import logging import random import itertools import colorsys -import matplotlib -# in case you are running on machine without display, e.g. server -if os.environ.get('DISPLAY', '') == '' \ - and matplotlib.rcParams['backend'] != 'agg': - logging.warning('No display found. Using non-interactive Agg backend') - # https://matplotlib.org/faq/usage_faq.html - matplotlib.use('Agg') - import numpy as np from skimage.measure import find_contours import matplotlib.pyplot as plt @@ -28,6 +21,11 @@ from matplotlib.patches import Polygon import IPython.display +# Root directory of the project +ROOT_DIR = os.path.abspath("../") + +# Import Mask RCNN +sys.path.append(ROOT_DIR) # To find local version of the library from mrcnn import utils diff --git a/samples/__init__.py b/samples/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samples/balloon/__init__.py b/samples/balloon/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samples/balloon/balloon.py b/samples/balloon/balloon.py index 3b3373459d..0dacd24e42 100644 --- a/samples/balloon/balloon.py +++ b/samples/balloon/balloon.py @@ -35,13 +35,10 @@ import skimage.draw # Root directory of the project -ROOT_DIR = os.getcwd() -if ROOT_DIR.endswith("samples/balloon"): - # Go up two levels to the repo root - ROOT_DIR = os.path.dirname(os.path.dirname(ROOT_DIR)) +ROOT_DIR = os.path.abspath("../../") # Import Mask RCNN -sys.path.append(ROOT_DIR) +sys.path.append(ROOT_DIR) # To find local version of the library from mrcnn.config import Config from mrcnn import model as modellib, utils diff --git a/samples/balloon/inspect_balloon_data.ipynb b/samples/balloon/inspect_balloon_data.ipynb index 57d25f8459..a25c4c01dc 100644 --- a/samples/balloon/inspect_balloon_data.ipynb +++ b/samples/balloon/inspect_balloon_data.ipynb @@ -42,13 +42,10 @@ "from matplotlib.patches import Polygon\n", "\n", "# Root directory of the project\n", - "ROOT_DIR = os.getcwd()\n", - "if ROOT_DIR.endswith(\"samples/balloon\"):\n", - " # Go up two levels to the repo root\n", - " ROOT_DIR = os.path.dirname(os.path.dirname(ROOT_DIR))\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", "\n", "# Import Mask RCNN\n", - "sys.path.append(ROOT_DIR)\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "from mrcnn import utils\n", "from mrcnn import visualize\n", "from mrcnn.visualize import display_images\n", diff --git a/samples/balloon/inspect_balloon_model.ipynb b/samples/balloon/inspect_balloon_model.ipynb index e6481f2fd6..f8923dde71 100644 --- a/samples/balloon/inspect_balloon_model.ipynb +++ b/samples/balloon/inspect_balloon_model.ipynb @@ -38,13 +38,10 @@ "import matplotlib.patches as patches\n", "\n", "# Root directory of the project\n", - "ROOT_DIR = os.getcwd()\n", - "if ROOT_DIR.endswith(\"samples/balloon\"):\n", - " # Go up two levels to the repo root\n", - " ROOT_DIR = os.path.dirname(os.path.dirname(ROOT_DIR))\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", "\n", "# Import Mask RCNN\n", - "sys.path.append(ROOT_DIR)\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "from mrcnn import utils\n", "from mrcnn import visualize\n", "from mrcnn.visualize import display_images\n", diff --git a/samples/coco/__init__.py b/samples/coco/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samples/coco/coco.py b/samples/coco/coco.py index 2379a6f904..962b657559 100644 --- a/samples/coco/coco.py +++ b/samples/coco/coco.py @@ -28,6 +28,7 @@ """ import os +import sys import time import numpy as np import imgaug # https://github.com/aleju/imgaug (pip3 install imageaug) @@ -46,12 +47,14 @@ import urllib.request import shutil +# Root directory of the project +ROOT_DIR = os.path.abspath("../../") + +# Import Mask RCNN +sys.path.append(ROOT_DIR) # To find local version of the library from mrcnn.config import Config from mrcnn import model as modellib, utils -# Root directory of the project -ROOT_DIR = os.getcwd() - # Path to trained weights file COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5") diff --git a/samples/coco/inspect_data.ipynb b/samples/coco/inspect_data.ipynb index d824eccf8c..8a14f8d95a 100644 --- a/samples/coco/inspect_data.ipynb +++ b/samples/coco/inspect_data.ipynb @@ -39,15 +39,18 @@ "import matplotlib.lines as lines\n", "from matplotlib.patches import Polygon\n", "\n", + "# Root directory of the project\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", + "\n", + "# Import Mask RCNN\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "from mrcnn import utils\n", "from mrcnn import visualize\n", "from mrcnn.visualize import display_images\n", "import mrcnn.model as modellib\n", "from mrcnn.model import log\n", "\n", - "%matplotlib inline \n", - "\n", - "ROOT_DIR = os.getcwd()" + "%matplotlib inline" ] }, { diff --git a/samples/coco/inspect_model.ipynb b/samples/coco/inspect_model.ipynb index d177ba2c03..5a278ba616 100644 --- a/samples/coco/inspect_model.ipynb +++ b/samples/coco/inspect_model.ipynb @@ -35,6 +35,11 @@ "import matplotlib.pyplot as plt\n", "import matplotlib.patches as patches\n", "\n", + "# Root directory of the project\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", + "\n", + "# Import Mask RCNN\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "from mrcnn import utils\n", "from mrcnn import visualize\n", "from mrcnn.visualize import display_images\n", @@ -43,9 +48,6 @@ "\n", "%matplotlib inline \n", "\n", - "# Root directory of the project\n", - "ROOT_DIR = os.getcwd()\n", - "\n", "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", diff --git a/samples/coco/inspect_weights.ipynb b/samples/coco/inspect_weights.ipynb index 2866c436c0..3443ad9df1 100644 --- a/samples/coco/inspect_weights.ipynb +++ b/samples/coco/inspect_weights.ipynb @@ -31,6 +31,11 @@ "import matplotlib.pyplot as plt\n", "import keras\n", "\n", + "# Root directory of the project\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", + "\n", + "# Import Mask RCNN\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "from mrcnn import utils\n", "import mrcnn.model as modellib\n", "from mrcnn import visualize\n", @@ -38,9 +43,6 @@ "\n", "%matplotlib inline \n", "\n", - "# Root directory of the project\n", - "ROOT_DIR = os.getcwd()\n", - "\n", "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", @@ -179,7 +181,7 @@ ] }, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ diff --git a/samples/demo.ipynb b/samples/demo.ipynb index 34631425ee..e11c6e9f25 100644 --- a/samples/demo.ipynb +++ b/samples/demo.ipynb @@ -32,16 +32,20 @@ "import matplotlib\n", "import matplotlib.pyplot as plt\n", "\n", - "import coco\n", + "# Root directory of the project\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", + "\n", + "# Import Mask RCNN\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "import mrcnn.utils\n", "import mrcnn.model as modellib\n", "import mrcnn.visualize\n", + "# Import COCO config\n", + "sys.path.append(os.path.join(ROOT_DIR, \"samples/coco/\")) # To find local version\n", + "import coco\n", "\n", "%matplotlib inline \n", "\n", - "# Root directory of the project\n", - "ROOT_DIR = os.getcwd()\n", - "\n", "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n", @@ -284,7 +288,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.2" + "version": "3.5.2" } }, "nbformat": 4, diff --git a/samples/shapes/__init__.py b/samples/shapes/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/samples/shapes/shapes.py b/samples/shapes/shapes.py index 2a44f3cc4f..f0c87ba130 100644 --- a/samples/shapes/shapes.py +++ b/samples/shapes/shapes.py @@ -9,11 +9,18 @@ Written by Waleed Abdulla """ +import os +import sys import math import random import numpy as np import cv2 +# Root directory of the project +ROOT_DIR = os.path.abspath("../../") + +# Import Mask RCNN +sys.path.append(ROOT_DIR) # To find local version of the library from mrcnn.config import Config from mrcnn import utils diff --git a/samples/shapes/train_shapes.ipynb b/samples/shapes/train_shapes.ipynb index 981737c0d1..f29f2b16bf 100644 --- a/samples/shapes/train_shapes.ipynb +++ b/samples/shapes/train_shapes.ipynb @@ -37,6 +37,11 @@ "import matplotlib\n", "import matplotlib.pyplot as plt\n", "\n", + "# Root directory of the project\n", + "ROOT_DIR = os.path.abspath(\"../../\")\n", + "\n", + "# Import Mask RCNN\n", + "sys.path.append(ROOT_DIR) # To find local version of the library\n", "from mrcnn.config import Config\n", "from mrcnn import utils\n", "import mrcnn.model as modellib\n", @@ -45,9 +50,6 @@ "\n", "%matplotlib inline \n", "\n", - "# Root directory of the project\n", - "ROOT_DIR = os.getcwd()\n", - "\n", "# Directory to save logs and trained model\n", "MODEL_DIR = os.path.join(ROOT_DIR, \"logs\")\n", "\n",