Skip to content

Commit

Permalink
add stochastic depth according to code
Browse files Browse the repository at this point in the history
  • Loading branch information
gau-nernst committed Aug 19, 2023
1 parent cb2c5f8 commit 9ceb287
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vision_toolbox/backbones/convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def __init__(
super().__init__()
self.stem = nn.Sequential(nn.Conv2d(3, d_model, 4, 4), Permute(0, 2, 3, 1), norm(d_model))

stochastic_depth_rates = torch.linspace(0, stochastic_depth, sum(depths))
self.stages = nn.Sequential()

for stage_idx, depth in enumerate(depths):
stage = nn.Sequential()
if stage_idx > 0:
Expand All @@ -71,8 +73,9 @@ def __init__(
downsample = nn.Identity()
stage.append(downsample)

for _ in range(depth):
block = ConvNeXtBlock(d_model, expansion_ratio, bias, layer_scale_init, stochastic_depth, norm, act)
for block_idx in range(depth):
rate = stochastic_depth_rates[sum(depths[:stage_idx]) + block_idx]
block = ConvNeXtBlock(d_model, expansion_ratio, bias, layer_scale_init, rate, norm, act)
stage.append(block)

self.stages.append(stage)
Expand Down

0 comments on commit 9ceb287

Please sign in to comment.