Skip to content

Commit df9beed

Browse files
added augmentation
1 parent 0345f92 commit df9beed

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

config/conf.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
"optimizer":"adam",
66
"metrics":["mIoU", "oneHotIoU", "mse", "oneHotMeanIoU"],
77
"loss":"focal",
8-
"monitor_metric":"val_one_hot_mean_io_u"
8+
"monitor_metric":"val_one_hot_mean_io_u",
9+
"augmentation":{
10+
"toGray":1,
11+
"horizontalFlip":1,
12+
"verticalFlip":1,
13+
"clahe":1
14+
}
915
}

src/utils/augmentation_pipeline.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import albumentations as A
2+
3+
def get_transformation_pipeline(augmentation=[]):
4+
augmentation_pipeline = []
5+
for t, p in augmentation:
6+
transformation = A.OneOf([
7+
t
8+
],p = p)
9+
augmentation_pipeline.append(transformation)
10+
11+
return A.Compose(augmentation_pipeline)

src/utils/conf_reader.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import tensorflow as tf
3-
from utils.losses import LOSSES
3+
import albumentations as A
4+
from augmentation_pipeline import get_transformation_pipeline
5+
from losses import LOSSES
46

57
OPTIMIZERS = {
68
'adam':tf.keras.optimizers.Adam,
@@ -14,6 +16,13 @@
1416
'mse':tf.keras.metrics.MeanSquaredError()
1517
}
1618

19+
AUGMENTATION = {
20+
"toGray":A.ToGray(),
21+
"horizontalFlip":A.HorizontalFlip(),
22+
"verticalFlip":A.VerticalFlip(),
23+
"clahe":A.CLAHE()
24+
}
25+
1726
def read_conf(filename):
1827
with open(filename,'r') as f:
1928
conf = json.load(f)
@@ -49,4 +58,10 @@ def read_conf(filename):
4958
else:
5059
conf['loss'] = LOSSES[conf['loss']]()
5160

61+
if not 'augmentation' in conf:
62+
conf['augmentation'] = A.Compose([])
63+
else:
64+
conf['augmentation'] = [(AUGMENTATION[x], p) for x, p in conf['augmentation'].items()]
65+
conf['augmentation'] = get_transformation_pipeline(conf['augmentation'])
66+
5267
return conf

0 commit comments

Comments
 (0)