MCPcopy Create free account
hub / github.com/JunlinHan/DCLGAN / LinearBlock

Class LinearBlock

models/networks.py:871–913  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

869
870
871class LinearBlock(nn.Module):
872 def __init__(self, input_dim, output_dim, norm='none', activation='relu'):
873 super(LinearBlock, self).__init__()
874 use_bias = True
875 # initialize fully connected layer
876 self.fc = nn.Linear(input_dim, output_dim, bias=use_bias)
877
878 # initialize normalization
879 norm_dim = output_dim
880 if norm == 'batch':
881 self.norm = nn.BatchNorm1d(norm_dim)
882 elif norm == 'inst':
883 self.norm = nn.InstanceNorm1d(norm_dim)
884 elif norm == 'ln':
885 self.norm = LayerNorm(norm_dim)
886 elif norm == 'none':
887 self.norm = None
888 else:
889 assert 0, "Unsupported normalization: {}".format(norm)
890
891 # initialize activation
892 if activation == 'relu':
893 self.activation = nn.ReLU(inplace=True)
894 elif activation == 'lrelu':
895 self.activation = nn.LeakyReLU(0.2, inplace=True)
896 elif activation == 'prelu':
897 self.activation = nn.PReLU()
898 elif activation == 'selu':
899 self.activation = nn.SELU(inplace=True)
900 elif activation == 'tanh':
901 self.activation = nn.Tanh()
902 elif activation == 'none':
903 self.activation = None
904 else:
905 assert 0, "Unsupported activation: {}".format(activation)
906
907 def forward(self, x):
908 out = self.fc(x)
909 if self.norm:
910 out = self.norm(out)
911 if self.activation:
912 out = self.activation(out)
913 return out
914
915##################################################################################
916# Normalization layers

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected