Skip to content

Commit

Permalink
Revert "Merge pull request #1 from John1231983/master"
Browse files Browse the repository at this point in the history
This reverts commit 6881764, reversing
changes made to 0222d46.
  • Loading branch information
killthekitten committed Mar 4, 2018
1 parent a658803 commit 3d82d90
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 121 deletions.
12 changes: 6 additions & 6 deletions bowl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ class BowlConfig(Config):
# Train on 1 GPU and 8 images per GPU. We can put multiple images on each
# GPU because the images are small. Batch size is 8 (GPUs * images/GPU).
GPU_COUNT = 1
IMAGES_PER_GPU = 2
IMAGES_PER_GPU = 1

# Number of classes (including background)
NUM_CLASSES = 1 + 1 # background + nuclei

# Use small images for faster training. Set the limits of the small side
# the large side, and that determines the image shape.
IMAGE_MIN_DIM = 512
IMAGE_MAX_DIM = 512
IMAGE_MIN_DIM = 256
IMAGE_MAX_DIM = 256

# Use smaller anchors because our image and objects are small
RPN_ANCHOR_SCALES = (8, 16, 32, 64, 128) # anchor side in pixels

# Reduce training ROIs per image because the images are small and have
# few objects. Aim to allow ROI sampling to pick 33% positive ROIs.
TRAIN_ROIS_PER_IMAGE = 600
TRAIN_ROIS_PER_IMAGE = 1000

STEPS_PER_EPOCH = None

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

USE_MINI_MASK = True
USE_MINI_MASK = False

bowl_config = BowlConfig()
bowl_config.display()
bowl_config.display()
10 changes: 5 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 Down
93 changes: 0 additions & 93 deletions functions.py

This file was deleted.

34 changes: 24 additions & 10 deletions inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from inference_config import inference_config
from bowl_dataset import BowlDataset
from utils import rle_encode, rle_decode, rle_to_string
import functions as f

ROOT_DIR = os.getcwd()
MODEL_DIR = os.path.join(ROOT_DIR, "logs")

Expand All @@ -32,8 +32,7 @@

output = []
sample_submission = pd.read_csv('stage1_sample_submission.csv')
ImageId = []
EncodedPixels = []

for image_id in tqdm(sample_submission.ImageId):
image_path = os.path.join('stage1_test', image_id, 'images', image_id + '.png')

Expand All @@ -42,10 +41,25 @@
r = results[0]

masks = r['masks']
ImageId_batch, EncodedPixels_batch = f.numpy2encoding_no_overlap2(masks, image_id, r['scores'])
ImageId += ImageId_batch
EncodedPixels += EncodedPixels_batch



f.write2csv('submission_v2.csv', ImageId, EncodedPixels)

count = masks.shape[-1]
occlusion = np.logical_not(masks[:, :, -1]).astype(np.uint8)

for i in range(count - 2, -1, -1):
mask = masks[:, :, i] * occlusion
mask_rle = rle_to_string(rle_encode(mask))

# Sanity check
try:
rle_decode(mask_rle, original_image.shape[:-1])
output.append([image_id, mask_rle])
occlusion = np.logical_and(occlusion, np.logical_not(masks[:, :, i]))

except Exception as e:
print(e)
print(image_id)
print('---')

output_df = pd.DataFrame(output, columns=['ImageId', 'EncodedPixels'])
output_df.to_csv('submission.csv', index=False, encoding='utf-8')

2 changes: 1 addition & 1 deletion 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, "resnet101", 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
12 changes: 6 additions & 6 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
model_dir=MODEL_DIR)

# Which weights to start with?
init_with = "imagenet" # imagenet, coco, or last
init_with = "coco" # imagenet, coco, or last

if init_with == "imagenet":
model.load_weights(model.get_imagenet_weights(), by_name=True)
Expand Down Expand Up @@ -57,12 +57,12 @@
# Passing layers="heads" freezes all layers except the head
# layers. You can also pass a regular expression to select
# which layers to train by name pattern.
#model.train(dataset_train, dataset_val,
# learning_rate=bowl_config.LEARNING_RATE,
# epochs=1,
# layers='heads')
model.train(dataset_train, dataset_val,
learning_rate=bowl_config.LEARNING_RATE,
epochs=1,
layers='heads')

model.train(dataset_train, dataset_val,
learning_rate=bowl_config.LEARNING_RATE / 10,
epochs=100,
layers="all")
layers="all")

0 comments on commit 3d82d90

Please sign in to comment.