forked from seung-lab/DeepEM
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(augment): add augmentation for 16nm data
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from augmentor import * | ||
|
||
|
||
def get_augmentation( | ||
is_train, | ||
box=None, | ||
missing=7, | ||
blur=7, | ||
lost=True, | ||
random=False, | ||
recompute=False, | ||
border=False, | ||
**kwargs | ||
): | ||
augs = list() | ||
|
||
# Box | ||
if is_train: | ||
if box == 'noise': | ||
augs.append( | ||
NoiseBox(sigma=(1,3), dims=(3,13), margin=(1,3,3), | ||
density=0.3, skip=0.1) | ||
) | ||
elif box == 'fill': | ||
augs.append( | ||
FillBox(dims=(3,13), margin=(1,3,3), | ||
density=0.3, skip=0.1) | ||
) | ||
|
||
# Brightness & contrast purterbation | ||
augs.append( | ||
MixedGrayscale2D( | ||
contrast_factor=0.5, | ||
brightness_factor=0.5, | ||
prob=1, skip=0.3)) | ||
|
||
# Missing section & misalignment | ||
to_blend = list() | ||
# Misalingments | ||
trans = Compose([Misalign((0, 3), margin=1), | ||
Misalign((0, 8), margin=1), | ||
Misalign((0,13), margin=1)]) | ||
|
||
# Out-of-alignments | ||
slip = Compose([SlipMisalign((0, 3), interp=True, margin=1), | ||
SlipMisalign((0, 8), interp=True, margin=1), | ||
SlipMisalign((0,13), interp=True, margin=1)]) | ||
to_blend.append(Blend([trans,slip], props=[0.7,0.3])) | ||
if is_train: | ||
to_blend.append(Blend([ | ||
MisalignPlusMissing((2,8), value=0, random=random), | ||
MisalignPlusMissing((2,8), value=0, random=False) | ||
])) | ||
else: | ||
to_blend.append(MisalignPlusMissing((2,8), value=0, random=False)) | ||
if missing > 0: | ||
if is_train: | ||
to_blend.append(Blend([ | ||
MixedMissingSection(maxsec=missing, individual=True, value=0, random=False), | ||
MixedMissingSection(maxsec=missing, individual=True, value=0, random=random), | ||
MissingSection(maxsec=missing, individual=False, value=0, random=random), | ||
])) | ||
else: | ||
to_blend.append( | ||
MixedMissingSection(maxsec=missing, individual=True, value=0, random=False) | ||
) | ||
if lost: | ||
if is_train: | ||
to_blend.append(Blend([ | ||
LostSection(1), | ||
LostPlusMissing(value=0, random=random), | ||
LostPlusMissing(value=0, random=False) | ||
])) | ||
augs.append(Blend(to_blend)) | ||
|
||
# Out-of-focus | ||
if blur > 0: | ||
augs.append(MixedBlurrySection(maxsec=blur)) | ||
|
||
# Warping | ||
if is_train: | ||
augs.append(Warp(skip=0.3, do_twist=False, rot_max=45.0, scale_max=1.1)) | ||
|
||
# Recompute connected components | ||
if recompute: | ||
augs.append(Label()) | ||
|
||
# Flip & rotate | ||
augs.append(FlipRotate()) | ||
|
||
# Create border | ||
if border: | ||
augs.append(Border()) | ||
|
||
return Compose(augs) |