Skip to content

Commit

Permalink
Add: argparser for change config dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiyou12 committed Oct 18, 2018
1 parent 806adc5 commit 396a645
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
39 changes: 34 additions & 5 deletions dish.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class DishConfig(Config):

# Max number of final detections per image
DETECTION_MAX_INSTANCES = 100

def __init__(self, **kwargs):
self.__dict__.update(kwargs)


class DishIngerenceConfig(DishConfig):
Expand Down Expand Up @@ -235,15 +238,34 @@ def train(model):
dataset_val.load_dish(args.dataset, "val")
dataset_val.prepare()

augmentation = iaa.SomeOf((0, 2), [
iaa.Fliplr(0.5),
iaa.OneOf([iaa.Affine(rotate=90),
iaa.Affine(rotate=180),
iaa.Affine(rotate=270),
iaa.Affine(rotate=45),
iaa.Affine(rotate=135)]),
iaa.Multiply((0.8, 1.5)),
iaa.GaussianBlur(sigma=(0.0, 5.0))
])

# *** This training schedule is an example. Update to your needs ***
# Since we're using a very small dataset, and starting from
# COCO trained weights, we don't need to train too long. Also,
# no need to train all layers, just the heads should do it.
print("Training network heads")
model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=30,
layers='heads')
epochs=20,
layers='heads',
augmentation=augmentation)

print("Fine tune Resnet stage 4 and up")
model.train(dataset_train, dataset_val,
learning_rate=config.LEARNING_RATE,
epochs=40,
layers='4+',
augmentation=augmentation)


def color_splash(image, mask):
Expand Down Expand Up @@ -331,8 +353,8 @@ def detect_and_color_splash(model, image_path=None, video_path=None):
metavar="<command>",
help="'train' or 'splash'")
parser.add_argument('--dataset', required=False,
metavar="/path/to/balloon/dataset/",
help='Directory of the Balloon dataset')
metavar="/path/to/dish/dataset/",
help='Directory of the dish dataset')
parser.add_argument('--weights', required=True,
metavar="/path/to/weights.h5",
help="Path to weights .h5 file or 'coco'")
Expand All @@ -346,6 +368,11 @@ def detect_and_color_splash(model, image_path=None, video_path=None):
parser.add_argument('--video', required=False,
metavar="path or URL to video",
help='Video to apply the color splash effect on')
parser.add_argument('--pairs', required=False,
metavar="key=value",
help="Key values to apply config",
action='append',
type=lambda kv: kv.split("="))
args = parser.parse_args()

# Validate arguments
Expand All @@ -358,10 +385,11 @@ def detect_and_color_splash(model, image_path=None, video_path=None):
print("Weights: ", args.weights)
print("Dataset: ", args.dataset)
print("Logs: ", args.logs)
print("Keypairs: ", args.pairs)

# Configurations
if args.command == "train":
config = DishConfig()
config = DishConfig(**dict(args.pairs))
else:
config = DishIngerenceConfig()
config.display()
Expand Down Expand Up @@ -409,3 +437,4 @@ def detect_and_color_splash(model, image_path=None, video_path=None):
else:
print("'{}' is not recognized. "
"Use 'train' or 'splash'".format(args.command))

2 changes: 1 addition & 1 deletion setting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ source activate tensorflow_p36
tensorboard --logdir=${PWD}/logs

# 9. Run in tensorflow docker
nvidia-docker run -it -p 8889:8888 -p 6007:6006 -v ${PWD}:~/notebooks/works tensorflow/tensorflow:latest-gpu-py3
nvidia-docker run -it -p 8889:8888 -p 6007:6006 -v ${PWD}:/notebooks/works tensorflow/tensorflow:latest-gpu-py3
pip install scikit-image==0.13.1 imgaug opencv-python
apt-get install -y libsm6 libxext6 libxrender-dev

0 comments on commit 396a645

Please sign in to comment.