Skip to content

Commit

Permalink
Fix ROOT_DIR and other misc updates.
Browse files Browse the repository at this point in the history
- Update ROOT_DIR depending on path of file
- Remove unneeded __init__.py files
- Remove setting matplotlib backend
  • Loading branch information
waleedka committed Apr 7, 2018
1 parent 6a3a264 commit 24f6d07
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 48 deletions.
5 changes: 3 additions & 2 deletions mrcnn/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import random
import datetime
import re
import math
import logging
from collections import OrderedDict
import multiprocessing
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions mrcnn/parallel_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions mrcnn/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@
"""

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
from matplotlib import patches, lines
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


Expand Down
Empty file removed samples/__init__.py
Empty file.
Empty file removed samples/balloon/__init__.py
Empty file.
7 changes: 2 additions & 5 deletions samples/balloon/balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions samples/balloon/inspect_balloon_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions samples/balloon/inspect_balloon_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file removed samples/coco/__init__.py
Empty file.
9 changes: 6 additions & 3 deletions samples/coco/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""

import os
import sys
import time
import numpy as np
import imgaug # https://github.com/aleju/imgaug (pip3 install imageaug)
Expand All @@ -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")

Expand Down
9 changes: 6 additions & 3 deletions samples/coco/inspect_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down
8 changes: 5 additions & 3 deletions samples/coco/inspect_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions samples/coco/inspect_weights.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@
"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",
"from mrcnn.model import log\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",
Expand Down Expand Up @@ -179,7 +181,7 @@
]
},
"metadata": {},
"output_type": "execute_result"
"output_type": "display_data"
}
],
"source": [
Expand Down
14 changes: 9 additions & 5 deletions samples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -284,7 +288,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
"version": "3.5.2"
}
},
"nbformat": 4,
Expand Down
Empty file removed samples/shapes/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions samples/shapes/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions samples/shapes/train_shapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 24f6d07

Please sign in to comment.