Skip to content

Commit 1ff710b

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

File tree

5 files changed

+126
-1
lines changed

5 files changed

+126
-1
lines changed

deepem/data/augment/cortex/aug_16nm.py

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

deepem/data/augment/cortex/aug_4nm.py

+6
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

+6
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

+4-1
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)