Skip to content

Commit

Permalink
Built in flatten (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
qubvel authored Sep 14, 2021
1 parent b78f4ba commit 15418da
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
4 changes: 2 additions & 2 deletions segmentation_models_pytorch/base/heads.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch.nn as nn
from .modules import Flatten, Activation
from .modules import Activation


class SegmentationHead(nn.Sequential):
Expand All @@ -17,7 +17,7 @@ def __init__(self, in_channels, classes, pooling="avg", dropout=0.2, activation=
if pooling not in ("max", "avg"):
raise ValueError("Pooling should be one of ('max', 'avg'), got {}.".format(pooling))
pool = nn.AdaptiveAvgPool2d(1) if pooling == 'avg' else nn.AdaptiveMaxPool2d(1)
flatten = Flatten()
flatten = nn.Flatten()
dropout = nn.Dropout(p=dropout, inplace=True) if dropout else nn.Identity()
linear = nn.Linear(in_channels, classes, bias=True)
activation = Activation(activation)
Expand Down
5 changes: 0 additions & 5 deletions segmentation_models_pytorch/base/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,3 @@ def __init__(self, name, **params):

def forward(self, x):
return self.attention(x)


class Flatten(nn.Module):
def forward(self, x):
return x.view(x.shape[0], -1)

0 comments on commit 15418da

Please sign in to comment.