Skip to content

Commit

Permalink
Add RESNET_ARCHITECTURE variable and change config.py to its original…
Browse files Browse the repository at this point in the history
… state
  • Loading branch information
killthekitten committed Mar 4, 2018
1 parent ec69200 commit 1c03b9c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ I did almost no changes to the original code, except for:
* `VALIDATION_STEPS` and `STEPS_PER_EPOCH` are now forced to depend on the dataset size, hardcoded.
* `multiprocessing=False`, hardcoded.
* [@John1231983]'s changed from [this PR](https://github.com/killthekitten/kaggle-ds-bowl-2018-baseline/pull/1).
* Added `RESNET_ARCHITECTURE` variable to the config (`resnet50` or `resnet101` while 101 comes with a default config).

## Quick Start

Expand Down Expand Up @@ -42,7 +43,7 @@ CUDA_VISIBLE_DEVICES="0" python inference.py

This will create `submission.csv` in the repo and overwrite the old one (you're welcome to fix this with a PR).

6. Submit! You should get around 0.342 score on LB after 100 epochs.
6. Submit! You should get around 0.4 score on LB after 100 epochs.

## What's else inside?

Expand Down
11 changes: 9 additions & 2 deletions bowl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ class BowlConfig(Config):

# use small validation steps since the epoch is small
VALIDATION_STEPS = 5

USE_MINI_MASK = True


MAX_GT_INSTANCES = 256

DETECTION_MAX_INSTANCES = 512

RESNET_ARCHITECTURE = "resnet50"


bowl_config = BowlConfig()
bowl_config.display()
12 changes: 7 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Config(object):
# Validation stats are also calculated at each epoch end and they
# might take a while, so don't set this too small to avoid spending
# a lot of time on validation stats.
STEPS_PER_EPOCH = 670
STEPS_PER_EPOCH = 1000

# Number of validation steps to run at the end of every training epoch.
# A bigger number improves accuracy of validation stats, but slows
Expand Down Expand Up @@ -87,8 +87,8 @@ class Config(object):
# Images are resized such that the smallest side is >= IMAGE_MIN_DIM and
# the longest side is <= IMAGE_MAX_DIM. In case both conditions can't
# be satisfied together the IMAGE_MAX_DIM is enforced.
IMAGE_MIN_DIM = 512
IMAGE_MAX_DIM = 512
IMAGE_MIN_DIM = 800
IMAGE_MAX_DIM = 1024
# If True, pad images with zeros such that they're (max_dim by max_dim)
IMAGE_PADDING = True # currently, the False option is not supported

Expand All @@ -111,14 +111,14 @@ class Config(object):
MASK_SHAPE = [28, 28]

# Maximum number of ground truth instances to use in one image
MAX_GT_INSTANCES = 256
MAX_GT_INSTANCES = 100

# Bounding box refinement standard deviation for RPN and final detections.
RPN_BBOX_STD_DEV = np.array([0.1, 0.1, 0.2, 0.2])
BBOX_STD_DEV = np.array([0.1, 0.1, 0.2, 0.2])

# Max number of final detections
DETECTION_MAX_INSTANCES = 512
DETECTION_MAX_INSTANCES = 100

# Minimum probability value to accept a detected instance
# ROIs below this threshold are skipped
Expand All @@ -144,6 +144,8 @@ class Config(object):
# train the RPN.
USE_RPN_ROIS = True

RESNET_ARCHITECTURE = "resnet101"

def __init__(self):
"""Set values of computed attributes."""
# Effective batch size
Expand Down
6 changes: 3 additions & 3 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ def build(self, mode, config):
# Bottom-up Layers
# Returns a list of the last layers of each stage, 5 in total.
# Don't create the thead (stage 5), so we pick the 4th item in the list.
_, C2, C3, C4, C5 = resnet_graph(input_image, "resnet50", stage5=True)
_, C2, C3, C4, C5 = resnet_graph(input_image, config.RESNET_ARCHITECTURE, stage5=True)
# Top-down Layers
# TODO: add assert to varify feature map sizes match what's in config
P5 = KL.Conv2D(256, (1, 1), name='fpn_c5p5')(C5)
Expand Down Expand Up @@ -2224,10 +2224,10 @@ def train(self, train_dataset, val_dataset, learning_rate, epochs, layers):
workers = 0
else:
workers = max(self.config.BATCH_SIZE // 2, 2)

steps_per_epoch = np.ceil(len(train_dataset.image_ids) / self.config.BATCH_SIZE)
validation_steps = np.ceil(len(train_dataset.image_ids) / self.config.BATCH_SIZE)

self.keras_model.fit_generator(
train_generator,
initial_epoch=self.epoch,
Expand Down

0 comments on commit 1c03b9c

Please sign in to comment.