Skip to content

Commit da926bd

Browse files
committed
feat: section gap augmentation
1 parent cf140b6 commit da926bd

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

deepem/data/augment/cortex/aug_16nm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def get_augmentation(
1010
random=False,
1111
recompute=False,
1212
border=[],
13+
section_gap=0,
14+
mask_section_gap=False,
1315
**kwargs
1416
):
1517
augs = list()
@@ -92,4 +94,8 @@ def get_augmentation(
9294
if recompute:
9395
augs.append(Label(targets=recompute))
9496

97+
# Section gap
98+
if section_gap > 0:
99+
augs.append(SectionGap(num_secs=section_gap, masked=mask_section_gap))
100+
95101
return Compose(augs)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
from augmentor import *
2+
3+
4+
def get_augmentation(
5+
is_train,
6+
box=None,
7+
missing=7,
8+
blur=7,
9+
lost=True,
10+
random=False,
11+
recompute=False,
12+
border=[],
13+
mask_section_gap=False,
14+
**kwargs
15+
):
16+
augs = list()
17+
18+
# Box
19+
if is_train:
20+
if box == 'noise':
21+
augs.append(
22+
NoiseBox(sigma=(1, 3), dims=(3, 13), margin=(1, 3, 3),
23+
density=0.3, skip=0.1)
24+
)
25+
elif box == 'fill':
26+
augs.append(
27+
FillBox(dims=(3, 13), margin=(1, 3, 3),
28+
density=0.3, skip=0.1)
29+
)
30+
31+
# Brightness & contrast purterbation
32+
augs.append(
33+
MixedGrayscale2D(
34+
contrast_factor=0.5,
35+
brightness_factor=0.5,
36+
prob=1, skip=0.3))
37+
38+
# Missing section & misalignment
39+
to_blend = list()
40+
# Misalingments
41+
trans = Compose([Misalign((0, 3), margin=1),
42+
Misalign((0, 8), margin=1),
43+
Misalign((0, 13), margin=1)])
44+
45+
# Out-of-alignments
46+
slip = Compose([SlipMisalign((0, 3), interp=True, margin=1),
47+
SlipMisalign((0, 8), interp=True, margin=1),
48+
SlipMisalign((0, 13), interp=True, margin=1)])
49+
to_blend.append(Blend([trans, slip], props=[0.7, 0.3]))
50+
if is_train:
51+
to_blend.append(Blend([
52+
MisalignPlusMissing((2, 8), value=0, random=random),
53+
MisalignPlusMissing((2, 8), value=0, random=False)
54+
]))
55+
else:
56+
to_blend.append(MisalignPlusMissing((2, 8), value=0, random=False))
57+
if missing > 0:
58+
if is_train:
59+
to_blend.append(Blend([
60+
MixedMissingSection(maxsec=missing, individual=True, value=0, random=False),
61+
MixedMissingSection(maxsec=missing, individual=True, value=0, random=random),
62+
MissingSection(maxsec=missing, individual=False, value=0, random=random),
63+
]))
64+
else:
65+
to_blend.append(
66+
MixedMissingSection(maxsec=missing, individual=True, value=0, random=False)
67+
)
68+
if lost:
69+
if is_train:
70+
to_blend.append(Blend([
71+
LostSection(1),
72+
LostPlusMissing(value=0, random=random),
73+
LostPlusMissing(value=0, random=False)
74+
]))
75+
augs.append(Blend(to_blend))
76+
77+
# Out-of-focus
78+
if blur > 0:
79+
augs.append(MixedBlurrySection(maxsec=blur))
80+
81+
# Warping
82+
if is_train:
83+
augs.append(Warp(skip=0.3, do_twist=False, rot_max=45.0, scale_max=1.1))
84+
85+
# Flip & rotate
86+
augs.append(FlipRotate())
87+
88+
# Create border
89+
if border:
90+
augs.append(Border(targets=border))
91+
92+
# Recompute connected components
93+
if recompute:
94+
augs.append(Label(targets=recompute))
95+
96+
# Section gap
97+
augs.append(
98+
Blend([
99+
SectionGap(num_secs=3, masked=mask_section_gap),
100+
SectionGap(num_secs=4, masked=mask_section_gap),
101+
SectionGap(num_secs=5, masked=mask_section_gap),
102+
])
103+
)
104+
105+
return Compose(augs)

deepem/data/augment/cortex/aug_4nm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def get_augmentation(
1010
random=False,
1111
recompute=False,
1212
border=[],
13+
section_gap=0,
14+
mask_section_gap=False,
1315
**kwargs
1416
):
1517
augs = list()
@@ -92,4 +94,8 @@ def get_augmentation(
9294
if recompute:
9395
augs.append(Label(targets=recompute))
9496

97+
# Section gap
98+
if section_gap > 0:
99+
augs.append(SectionGap(num_secs=section_gap, masked=mask_section_gap))
100+
95101
return Compose(augs)

deepem/data/augment/cortex/aug_8nm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def get_augmentation(
1010
random=False,
1111
recompute=False,
1212
border=[],
13+
section_gap=0,
14+
mask_section_gap=False,
1315
**kwargs
1416
):
1517
augs = list()
@@ -92,4 +94,8 @@ def get_augmentation(
9294
if recompute:
9395
augs.append(Label(targets=recompute))
9496

97+
# Section gap
98+
if section_gap > 0:
99+
augs.append(SectionGap(num_secs=section_gap, masked=mask_section_gap))
100+
95101
return Compose(augs)

deepem/train/option.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def initialize(self):
124124
self.parser.add_argument('--noise_min', type=float, default=0.01)
125125
self.parser.add_argument('--noise_max', type=float, default=0.1)
126126
self.parser.add_argument('--noise_per_channel', action='store_true')
127+
self.parser.add_argument('--section_gap', type=int, default=0)
128+
self.parser.add_argument('--mask_section_gap', action='store_true')
127129

128130
# Tilt-series electron tomography
129131
self.parser.add_argument('--tilt_series', type=int, default=0)
@@ -237,7 +239,8 @@ def parse(self):
237239

238240
# Data augmentation
239241
aug_keys = ['recompute', 'border', 'flip','grayscale','warping','misalign',
240-
'interp','missing','blur','box','mip','lost','random']
242+
'interp','missing','blur','box','mip','lost','random',
243+
'section_gap', 'mask_section_gap']
241244
opt.aug_params = {k: args[k] for k in aug_keys}
242245

243246
# Noise

0 commit comments

Comments
 (0)