Skip to content

Commit

Permalink
Add dropout
Browse files Browse the repository at this point in the history
  • Loading branch information
kuangliu committed Apr 2, 2020
1 parent 8080550 commit 81db756
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion models/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def __init__(self, cfg, num_classes=10):

def _make_layers(self, in_planes):
layers = []
b = 0
blocks = float(sum(x[2] for x in self.cfg))
for expansion, out_planes, num_blocks, kernel_size, stride in self.cfg:
strides = [stride] + [1] * (num_blocks - 1)
for stride in strides:
Expand All @@ -107,15 +109,17 @@ def _make_layers(self, in_planes):
stride,
expansion,
se_ratio=0.25,
drop_rate=0))
drop_rate=0.2 * b / blocks))
in_planes = out_planes
b += 1
return nn.Sequential(*layers)

def forward(self, x):
out = swish(self.bn1(self.conv1(x)))
out = self.layers(out)
out = F.adaptive_avg_pool2d(out, 1)
out = out.view(out.size(0), -1)
out = F.dropout(out, 0.2)
out = self.linear(out)
return out

Expand Down

0 comments on commit 81db756

Please sign in to comment.