Skip to content

Commit

Permalink
refactor structure
Browse files Browse the repository at this point in the history
* create package mrcnn
* move notebooks to samples
  • Loading branch information
Borda authored and waleedka committed Apr 6, 2018
1 parent 7920f6f commit 451d738
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 63 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ The goal is to improve OpenStreetMap by adding high quality baseball, soccer, te
[![Mask RCNN on 4K Video](assets/4k_video.gif)](https://www.youtube.com/watch?v=OOT3UIXZztE)

# Getting Started
* [demo.ipynb](/demo.ipynb) Is the easiest way to start. It shows an example of using a model pre-trained on MS COCO to segment objects in your own images.
* [demo.ipynb](samples/demo.ipynb) Is the easiest way to start. It shows an example of using a model pre-trained on MS COCO to segment objects in your own images.
It includes code to run object detection and instance segmentation on arbitrary images.

* [train_shapes.ipynb](train_shapes.ipynb) shows how to train Mask R-CNN on your own dataset. This notebook introduces a toy dataset (Shapes) to demonstrate training on a new dataset.
* [train_shapes.ipynb](samples/train_shapes.ipynb) shows how to train Mask R-CNN on your own dataset. This notebook introduces a toy dataset (Shapes) to demonstrate training on a new dataset.

* ([model.py](model.py), [utils.py](utils.py), [config.py](config.py)): These files contain the main Mask RCNN implementation.
* ([model.py](mrcnn/model.py), [utils.py](mrcnn/utils.py), [config.py](mrcnn/config.py)): These files contain the main Mask RCNN implementation.


* [inspect_data.ipynb](/inspect_data.ipynb). This notebook visualizes the different pre-processing steps
* [inspect_data.ipynb](samples/inspect_data.ipynb). This notebook visualizes the different pre-processing steps
to prepare the training data.

* [inspect_model.ipynb](/inspect_model.ipynb) This notebook goes in depth into the steps performed to detect and segment objects. It provides visualizations of every step of the pipeline.
* [inspect_model.ipynb](samples/inspect_model.ipynb) This notebook goes in depth into the steps performed to detect and segment objects. It provides visualizations of every step of the pipeline.

* [inspect_weights.ipynb](/inspect_weights.ipynb)
* [inspect_weights.ipynb](samples/inspect_weights.ipynb)
This notebooks inspects the weights of a trained model and looks for anomalies and odd patterns.


# Step by Step Detection
To help with debugging and understanding the model, there are 3 notebooks
([inspect_data.ipynb](inspect_data.ipynb), [inspect_model.ipynb](inspect_model.ipynb),
[inspect_weights.ipynb](inspect_weights.ipynb)) that provide a lot of visualizations and allow running the model step by step to inspect the output at each point. Here are a few examples:
([inspect_data.ipynb](samples/inspect_data.ipynb), [inspect_model.ipynb](samples/inspect_model.ipynb),
[inspect_weights.ipynb](samples/inspect_weights.ipynb)) that provide a lot of visualizations and allow running the model step by step to inspect the output at each point. Here are a few examples:



Expand Down
5 changes: 2 additions & 3 deletions coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@
import urllib.request
import shutil

from config import Config
import utils
import model as modellib
from mrcnn.config import Config
from mrcnn import model as modellib, utils

# Root directory of the project
ROOT_DIR = os.getcwd()
Expand Down
18 changes: 18 additions & 0 deletions mrcnn/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import logging

import matplotlib
import numpy as np

# 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')

# parse the numpy versions
np_version = [int(i) for i in np.version.full_version.split('.')]
# comparing strings does not work for version lower 1.10
if np_version >= [1, 14]:
np.set_printoptions(legacy='1.13')
File renamed without changes.
16 changes: 5 additions & 11 deletions model.py → mrcnn/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
"""

import os
import sys
import glob
import random
import math
import datetime
import itertools
import json
import re
import logging
from collections import OrderedDict
Expand All @@ -25,11 +20,10 @@
import keras
import keras.backend as K
import keras.layers as KL
import keras.initializers as KI
import keras.engine as KE
import keras.models as KM

import utils
from mrcnn import utils

# Requires TensorFlow 1.3+ and Keras 2.0.8+.
from distutils.version import LooseVersion
Expand Down Expand Up @@ -1986,7 +1980,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='mask_rcnn')
model = KM.Model(inputs, outputs, name='mrcnn')
else:
# Network Heads
# Proposal classifier and BBox regressor heads
Expand All @@ -2012,11 +2006,11 @@ 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='mask_rcnn')
name='mrcnn')

# Add multi-GPU support.
if config.GPU_COUNT > 1:
from parallel_model import ParallelModel
from mrcnn.parallel_model import ParallelModel
model = ParallelModel(model, config.GPU_COUNT)

return model
Expand All @@ -2039,7 +2033,7 @@ def find_last(self):
dir_name = os.path.join(self.model_dir, dir_names[-1])
# Find the last checkpoint
checkpoints = next(os.walk(dir_name))[2]
checkpoints = filter(lambda f: f.startswith("mask_rcnn"), checkpoints)
checkpoints = filter(lambda f: f.startswith("mrcnn"), checkpoints)
checkpoints = sorted(checkpoints)
if not checkpoints:
return dir_name, None
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions shapes.py → mrcnn/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import numpy as np
import cv2

from config import Config
import utils
from mrcnn.config import Config
from mrcnn import utils


class ShapesConfig(Config):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion visualize.py → mrcnn/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from matplotlib.patches import Polygon
import IPython.display

import utils
from mrcnn import utils


############################################################
Expand Down
Empty file added samples/__init__.py
Empty file.
Empty file added samples/balloon/__init__.py
Empty file.
5 changes: 2 additions & 3 deletions samples/balloon/balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@

# Import Mask RCNN
sys.path.append(ROOT_DIR)
from config import Config
import utils
import model as modellib
from mrcnn.config import Config
from mrcnn import model as modellib, utils

# Path to trained weights file
COCO_WEIGHTS_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
Expand Down
12 changes: 6 additions & 6 deletions samples/balloon/inspect_balloon_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
"\n",
"# Import Mask RCNN\n",
"sys.path.append(ROOT_DIR)\n",
"import utils\n",
"import visualize\n",
"from visualize import display_images\n",
"import model as modellib\n",
"from model import log\n",
"import mrcnn.utils\n",
"import mrcnn.visualize\n",
"from mrcnn.visualize import display_images\n",
"import mrcnn.model as modellib\n",
"from mrcnn.model import log\n",
"\n",
"import balloon\n",
"from samples.balloon import balloon\n",
"\n",
"%matplotlib inline "
]
Expand Down
12 changes: 6 additions & 6 deletions samples/balloon/inspect_balloon_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
"\n",
"# Import Mask RCNN\n",
"sys.path.append(ROOT_DIR)\n",
"import utils\n",
"import visualize\n",
"from visualize import display_images\n",
"import model as modellib\n",
"from model import log\n",
"import mrcnn.utils\n",
"import mrcnn.visualize\n",
"from mrcnn.visualize import display_images\n",
"import mrcnn.model as modellib\n",
"from mrcnn.model import log\n",
"\n",
"import balloon\n",
"from samples.balloon import balloon\n",
"\n",
"%matplotlib inline \n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions demo.ipynb → samples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"import matplotlib.pyplot as plt\n",
"\n",
"import coco\n",
"import utils\n",
"import model as modellib\n",
"import visualize\n",
"import mrcnn.utils\n",
"import mrcnn.model as modellib\n",
"import mrcnn.visualize\n",
"\n",
"%matplotlib inline \n",
"\n",
Expand Down
10 changes: 5 additions & 5 deletions inspect_data.ipynb → samples/inspect_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
"import matplotlib.lines as lines\n",
"from matplotlib.patches import Polygon\n",
"\n",
"import utils\n",
"import visualize\n",
"from visualize import display_images\n",
"import model as modellib\n",
"from model import log\n",
"import mrcnn.utils\n",
"import mrcnn.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",
Expand Down
10 changes: 5 additions & 5 deletions inspect_model.ipynb → samples/inspect_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"import matplotlib.pyplot as plt\n",
"import matplotlib.patches as patches\n",
"\n",
"import utils\n",
"import visualize\n",
"from visualize import display_images\n",
"import model as modellib\n",
"from model import log\n",
"import mrcnn.utils\n",
"import mrcnn.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",
Expand Down
10 changes: 5 additions & 5 deletions inspect_weights.ipynb → samples/inspect_weights.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"import matplotlib.pyplot as plt\n",
"import keras\n",
"\n",
"import utils\n",
"import model as modellib\n",
"import visualize\n",
"from model import log\n",
"import mrcnn.utils\n",
"import mrcnn.model as modellib\n",
"import mrcnn.visualize\n",
"from mrcnn.model import log\n",
"\n",
"%matplotlib inline \n",
"\n",
Expand Down Expand Up @@ -179,7 +179,7 @@
]
},
"metadata": {},
"output_type": "display_data"
"output_type": "execute_result"
}
],
"source": [
Expand Down
10 changes: 5 additions & 5 deletions train_shapes.ipynb → samples/train_shapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from config import Config\n",
"import utils\n",
"import model as modellib\n",
"import visualize\n",
"from model import log\n",
"from mrcnn.config import Config\n",
"import mrcnn.utils\n",
"import mrcnn.model as modellib\n",
"import mrcnn.visualize\n",
"from mrcnn.model import log\n",
"\n",
"%matplotlib inline \n",
"\n",
Expand Down

0 comments on commit 451d738

Please sign in to comment.