Skip to content

Commit ea5d119

Browse files
committed
s/messy/partial_edge_blocks/g
1 parent c8b7af0 commit ea5d119

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

tests/layers/test_drop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_drop_filter(self):
7979
result = drop.drop_block_2d_drop_filter_(
8080
selection=selection,
8181
kernel=(2, 3),
82-
messy=False
82+
partial_edge_blocks=False
8383
).squeeze()
8484
print(result)
8585
assert result.device == torch.device(torch_device)
@@ -92,7 +92,7 @@ def test_drop_filter(self):
9292
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
9393
]
9494

95-
def test_drop_filter_messy(self):
95+
def test_drop_filter_partial_edge_blocks(self):
9696
selection = torch.tensor(
9797
[
9898
[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0],
@@ -108,7 +108,7 @@ def test_drop_filter_messy(self):
108108
result = drop.drop_block_2d_drop_filter_(
109109
selection=selection,
110110
kernel=(2, 3),
111-
messy=True
111+
partial_edge_blocks=True
112112
).squeeze()
113113
print(result)
114114
assert result.device == torch.device(torch_device)

timm/layers/drop.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def drop_block_2d_drop_filter_(
6464
*,
6565
selection,
6666
kernel: Tuple[int, int],
67-
messy: bool
67+
partial_edge_blocks: bool
6868
):
6969
"""Convert drop block gamma noise to a drop filter.
7070
@@ -75,13 +75,13 @@ def drop_block_2d_drop_filter_(
7575
`1.0` at the midpoints of selected blocks to drop,
7676
`0.0` everywhere else. Expected to be gamma noise.
7777
kernel: the shape of the 2d kernel.
78-
messy: permit partial blocks at the edges, faster.
78+
partial_edge_blocks: permit partial blocks at the edges, faster.
7979
8080
Returns:
8181
A drop filter, `1.0` at points to drop, `0.0` at points to keep.
8282
"""
8383

84-
if not messy:
84+
if not partial_edge_blocks:
8585
selection = selection * conv2d_kernel_midpoint_mask(
8686
shape=selection.shape[-2:],
8787
kernel=kernel,
@@ -111,7 +111,7 @@ def drop_block_2d(
111111
with_noise: bool = False,
112112
inplace: bool = False,
113113
batchwise: bool = False,
114-
messy: bool = False,
114+
partial_edge_blocks: bool = False,
115115
):
116116
"""DropBlock. See https://arxiv.org/pdf/1810.12890.pdf
117117
@@ -125,7 +125,7 @@ def drop_block_2d(
125125
with_noise: should normal noise be added to the dropped region?
126126
inplace: if the drop should be applied in-place on the input tensor.
127127
batchwise: should the entire batch use the same drop mask?
128-
messy: partial-blocks at the edges, faster.
128+
partial_edge_blocks: partial-blocks at the edges, faster.
129129
130130
Returns:
131131
If inplace, the modified `x`; otherwise, the dropped copy of `x`, on the same device.
@@ -156,7 +156,7 @@ def drop_block_2d(
156156
drop_filter = drop_block_2d_drop_filter_(
157157
selection=selection,
158158
kernel=kernel,
159-
messy=messy,
159+
partial_edge_blocks=partial_edge_blocks,
160160
)
161161
keep_filter = 1.0 - drop_filter
162162

@@ -210,7 +210,7 @@ def drop_block_fast_2d(
210210
with_noise=with_noise,
211211
inplace=inplace,
212212
batchwise=True,
213-
messy=True,
213+
partial_edge_blocks=True,
214214
)
215215

216216

@@ -224,15 +224,15 @@ class DropBlock2d(nn.Module):
224224
with_noise: should normal noise be added to the dropped region?
225225
inplace: if the drop should be applied in-place on the input tensor.
226226
batchwise: should the entire batch use the same drop mask?
227-
messy: partial-blocks at the edges, faster.
227+
partial_edge_blocks: partial-blocks at the edges, faster.
228228
"""
229229
drop_prob: float
230230
block_size: int
231231
gamma_scale: float
232232
with_noise: bool
233233
inplace: bool
234234
batchwise: bool
235-
messy: bool
235+
partial_edge_blocks: bool
236236

237237
def __init__(
238238
self,
@@ -242,7 +242,7 @@ def __init__(
242242
with_noise: bool = False,
243243
inplace: bool = False,
244244
batchwise: bool = False,
245-
messy: bool = True,
245+
partial_edge_blocks: bool = True,
246246
):
247247
super(DropBlock2d, self).__init__()
248248
self.drop_prob = drop_prob
@@ -251,7 +251,7 @@ def __init__(
251251
self.with_noise = with_noise
252252
self.inplace = inplace
253253
self.batchwise = batchwise
254-
self.messy = messy
254+
self.partial_edge_blocks = partial_edge_blocks
255255

256256
def forward(self, x):
257257
if not self.training or not self.drop_prob:
@@ -265,7 +265,7 @@ def forward(self, x):
265265
with_noise=self.with_noise,
266266
inplace=self.inplace,
267267
batchwise=self.batchwise,
268-
messy=self.messy)
268+
partial_edge_blocks=self.partial_edge_blocks)
269269

270270

271271
def drop_path(x, drop_prob: float = 0., training: bool = False, scale_by_keep: bool = True):

timm/models/resnet.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def make_blocks(
328328
drop_block_rate: float = 0.,
329329
drop_path_rate: float = 0.,
330330
drop_block_batchwise: bool = False,
331-
drop_block_messy: bool = True,
331+
drop_block_partial_edge_blocks: bool = True,
332332
**kwargs,
333333
) -> Tuple[List[Tuple[str, nn.Module]], List[Dict[str, Any]]]:
334334
"""Create ResNet stages with specified block configurations.
@@ -344,7 +344,7 @@ def make_blocks(
344344
avg_down: Use average pooling for downsample.
345345
drop_block_rate: DropBlock drop rate.
346346
drop_block_batchwise: Batchwise block dropping, faster.
347-
drop_block_messy: dropping produces partial blocks on the edge, faster.
347+
drop_block_partial_edge_blocks: dropping produces partial blocks on the edge, faster.
348348
drop_path_rate: Drop path rate for stochastic depth.
349349
**kwargs: Additional arguments passed to block constructors.
350350
@@ -364,7 +364,7 @@ def make_blocks(
364364
drop_blocks(
365365
drop_prob=drop_block_rate,
366366
batchwise=drop_block_batchwise,
367-
messy=drop_block_messy,
367+
partial_edge_blocks=drop_block_partial_edge_blocks,
368368
))):
369369
stage_name = f'layer{stage_idx + 1}' # never liked this name, but weight compat requires it
370370
stride = 1 if stage_idx == 0 else 2
@@ -468,7 +468,7 @@ def __init__(
468468
drop_path_rate: float = 0.,
469469
drop_block_rate: float = 0.,
470470
drop_block_batchwise: bool = True,
471-
drop_block_messy: bool = True,
471+
drop_block_partial_edge_blocks: bool = True,
472472
zero_init_last: bool = True,
473473
block_args: Optional[Dict[str, Any]] = None,
474474
):
@@ -500,7 +500,7 @@ def __init__(
500500
drop_path_rate (float): Stochastic depth drop-path rate (default 0.)
501501
drop_block_rate (float): Drop block rate (default 0.)
502502
drop_block_batchwise (bool): Sample blocks batchwise, faster.
503-
drop_block_messy (bool): Partial block dropping at the edges, faster.
503+
drop_block_partial_edge_blocks (bool): Partial block dropping at the edges, faster.
504504
zero_init_last (bool): zero-init the last weight in residual path (usually last BN affine weight)
505505
block_args (dict): Extra kwargs to pass through to block module
506506
"""
@@ -572,7 +572,7 @@ def __init__(
572572
aa_layer=aa_layer,
573573
drop_block_rate=drop_block_rate,
574574
drop_block_batchwise=drop_block_batchwise,
575-
drop_block_messy=drop_block_messy,
575+
drop_block_partial_edge_blocks=drop_block_partial_edge_blocks,
576576
drop_path_rate=drop_path_rate,
577577
**block_args,
578578
)
@@ -1470,7 +1470,7 @@ def resnet10t_dropblock_correct(pretrained: bool = False, **kwargs) -> ResNet:
14701470
avg_down=True,
14711471
drop_block_rate=0.05,
14721472
drop_block_batchwise=True,
1473-
drop_block_messy=True,
1473+
drop_block_partial_edge_blocks=True,
14741474
)
14751475
return _create_resnet('resnet10t', pretrained, **dict(model_args, **kwargs))
14761476

@@ -1486,7 +1486,7 @@ def resnet10t_dropblock_fast(pretrained: bool = False, **kwargs) -> ResNet:
14861486
avg_down=True,
14871487
drop_block_rate=0.05,
14881488
drop_block_batchwise=False,
1489-
drop_block_messy=False,
1489+
drop_block_partial_edge_blocks=False,
14901490
)
14911491
return _create_resnet('resnet10t', pretrained, **dict(model_args, **kwargs))
14921492

0 commit comments

Comments
 (0)