Skip to content

Commit

Permalink
changes in done while training- temp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeyaWagh committed Jun 3, 2018
1 parent f5dced7 commit 146aa62
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
6 changes: 6 additions & 0 deletions Mask_RCNN/mrcnn/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,10 @@ def mrcnn_mask_loss_graph(target_masks, target_class_ids, pred_masks):

# Compute binary cross entropy. If no positive ROIs, then return 0.
# shape: [batch, roi, num_classes]

# class_weights = tf.constant([[0.5, 2.0]])
# _weights = tf.reduce_sum(class_weights * y_true, axis=1)

loss = K.switch(tf.size(y_true) > 0,
K.binary_crossentropy(target=y_true, output=y_pred),
tf.constant(0.0))
Expand Down Expand Up @@ -2281,6 +2285,8 @@ def train(self, train_dataset, val_dataset, learning_rate, epochs, layers,
layer_regex = {
# all layers but the backbone
"heads": r"(mrcnn\_.*)|(rpn\_.*)|(fpn\_.*)",
"just_mrcnn_mask": r"(mrcnn\_mask.*)",
"heads_mask": r"(mrcnn\_mask.*)|(rpn\_.*)|(fpn\_.*)",
# From a specific Resnet stage and up
"3+": r"(res3.*)|(bn3.*)|(res4.*)|(bn4.*)|(res5.*)|(bn5.*)|(mrcnn\_.*)|(rpn\_.*)|(fpn\_.*)",
"4+": r"(res4.*)|(bn4.*)|(res5.*)|(bn5.*)|(mrcnn\_.*)|(rpn\_.*)|(fpn\_.*)",
Expand Down
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@

# LYFT Perception Challenge

---

## Training

<!-- Loss
![Header](./assets/Udacity_Header.png)

heads = 10 all = 40

![loss](./assets/loss_40.png)
# Lyft Perception Challenge

heads = 40 all = 100
---

![loss](./assets/loss2.png)
## About the challenge

Validation loss
## Approach

![val_loss](./assets/val_loss_40.png)
## Training

![val_loss](./assets/val_loss2.png) -->


| heads Epoch | all Epoch | loss | val_loss |
Expand All @@ -29,6 +25,18 @@ Validation loss
| 20 | 60 | ![loss](./assets/loss4.png) | ![val_loss](./assets/val_loss4.png) |



## Results

```
Your program runs at 1.730 FPS
Car F score: 0.455 | Car Precision: 0.243 | Car Recall: 0.582 | Road F score: 0.949 | Road Precision: 0.986 | Road Recall: 0.825 | Averaged F score: 0.702
```


## Inference and Submission

## Reference
https://github.com/matterport/Mask_RCNN
```
Expand All @@ -41,4 +49,8 @@ https://github.com/matterport/Mask_RCNN
howpublished = {\url{https://github.com/matterport/Mask_RCNN}},
commit = {6c9c82f5feaf5d729a72c67f33e139c4bc71399b}
}
```
```

## Author

Ameya Wagh [aywagh@wpi.edu](aywagh@wpi.edu)
Binary file added assets/Udacity_Header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 36 additions & 15 deletions train_mrcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
utils.download_trained_weights(COCO_MODEL_PATH)


class ShapesConfig(Config):
class LyftChallengeConfig(Config):
"""Configuration for training on the toy shapes dataset.
Derives from the base Config class and overrides values specific
to the toy shapes dataset.
Expand All @@ -49,7 +49,7 @@ class ShapesConfig(Config):
IMAGES_PER_GPU = 1

# Number of classes (including background)
NUM_CLASSES = 1 + 2 # background + 3 shapes
NUM_CLASSES = 1 + 2 # background + 2 shapes

# Use small images for faster training. Set the limits of the small side
# the large side, and that determines the image shape.
Expand All @@ -65,12 +65,12 @@ class ShapesConfig(Config):
TRAIN_ROIS_PER_IMAGE = 32

# Use a small epoch since the data is simple
STEPS_PER_EPOCH = 200
STEPS_PER_EPOCH = 100

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

config = ShapesConfig()
config = LyftChallengeConfig()
config.display()


Expand All @@ -81,6 +81,7 @@ class lyftDataset(utils.Dataset):
random_idx=0
def load_images(self,dataset_dir,dataset_type='train'):
image_paths = os.path.join(dataset_dir,'CameraRGB')
# image_paths = os.path.join(dataset_dir,'extraRGB')
images = os.listdir(image_paths)

self.add_class("shapes", 1, "road")
Expand Down Expand Up @@ -109,6 +110,7 @@ def load_image(self, image_id):
"""
# Load image
image = skimage.io.imread(self.image_info[image_id]['path'])
image = cv2.resize(image,(256,256))
# If grayscale. Convert to RGB for consistency.
if image.ndim != 3:
image = skimage.color.gray2rgb(image)
Expand All @@ -127,8 +129,10 @@ def load_mask(self,image_id):
return super(self.__class__, self).load_mask(image_id)
info = self.image_info[image_id]
mask_label = skimage.io.imread(os.path.join("./Train/CameraSeg",info["id"]))

# mask_label = skimage.io.imread(os.path.join("./Train/extraSeg",info["id"]))

mask = self.process_labels(mask_label[:,:,0])
mask = cv2.resize(mask,(256,256))

return mask,np.array([1,2], dtype=np.int32)

Expand Down Expand Up @@ -188,10 +192,10 @@ def image_reference(self, image_id):
iaa.Affine(rotate=270)]),
iaa.Multiply((0.8, 1.5)),
iaa.GaussianBlur(sigma=(0.0, 5.0)),
iaa.PiecewiseAffine(scale=(0.01, 0.05)),
# iaa.PiecewiseAffine(scale=(0.01, 0.05)),
iaa.Affine(scale=(0.5, 1.5)),
iaa.Affine(scale={"x": (0.5, 1.5), "y": (0.5, 1.5)}),
iaa.ElasticTransformation(alpha=(0, 5.0), sigma=0.25)
# iaa.ElasticTransformation(alpha=(0, 5.0), sigma=0.25)
])


Expand All @@ -204,6 +208,7 @@ def image_reference(self, image_id):
# exclude=["mrcnn_class_logits", "mrcnn_bbox_fc",
# "mrcnn_bbox", "mrcnn_mask"])

# model_path = os.path.join('./', "mask_rcnn_lyft.h5")
model_path = os.path.join('./', "mask_rcnn_lyft.h5")
# model_path = model.find_last()[1]

Expand All @@ -213,15 +218,31 @@ def image_reference(self, image_id):
model.load_weights(model_path, by_name=True)


model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=20,
augmentation=augmentation,
layers='heads')
print("Training ...")
# print(model.get_trainable_layers())
# exit()

# model.train(dataset_train, dataset_val,
# learning_rate=config.LEARNING_RATE,
# epochs=20,
# augmentation=augmentation,
# layers='heads')

# model.train(dataset_train, dataset_val,
# learning_rate=config.LEARNING_RATE / 100.0,
# epochs=10,
# augmentation=augmentation,
# layers="just_mrcnn_mask")

# model.train(dataset_train, dataset_val,
# learning_rate=config.LEARNING_RATE ,
# epochs=20,
# augmentation=augmentation,
# layers="heads")

model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE / 10,
epochs=60,
learning_rate=config.LEARNING_RATE/10.0,
epochs=30,
augmentation=augmentation,
layers="all")

Expand All @@ -232,7 +253,7 @@ def image_reference(self, image_id):

# inference

class InferenceConfig(ShapesConfig):
class InferenceConfig(LyftChallengeConfig):
GPU_COUNT = 1
IMAGES_PER_GPU = 1

Expand Down

0 comments on commit 146aa62

Please sign in to comment.