MCPcopy Create free account
hub / github.com/Lornatang/SRGAN-PyTorch / __init__

Method __init__

model.py:60–91  ·  view source on GitHub ↗
(
            self,
            net_cfg_name: str = "vgg19",
            batch_norm: bool = False,
            num_classes: int = 1000)

Source from the content-addressed store, hash-verified

58
59class _FeatureExtractor(nn.Module):
60 def __init__(
61 self,
62 net_cfg_name: str = "vgg19",
63 batch_norm: bool = False,
64 num_classes: int = 1000) -> None:
65 super(_FeatureExtractor, self).__init__()
66 self.features = _make_layers(net_cfg_name, batch_norm)
67
68 self.avgpool = nn.AdaptiveAvgPool2d((7, 7))
69
70 self.classifier = nn.Sequential(
71 nn.Linear(512 * 7 * 7, 4096),
72 nn.ReLU(True),
73 nn.Dropout(0.5),
74 nn.Linear(4096, 4096),
75 nn.ReLU(True),
76 nn.Dropout(0.5),
77 nn.Linear(4096, num_classes),
78 )
79
80 # Initialize neural network weights
81 for module in self.modules():
82 if isinstance(module, nn.Conv2d):
83 nn.init.kaiming_normal_(module.weight, mode="fan_out", nonlinearity="relu")
84 if module.bias is not None:
85 nn.init.constant_(module.bias, 0)
86 elif isinstance(module, nn.BatchNorm2d):
87 nn.init.constant_(module.weight, 1)
88 nn.init.constant_(module.bias, 0)
89 elif isinstance(module, nn.Linear):
90 nn.init.normal_(module.weight, 0, 0.01)
91 nn.init.constant_(module.bias, 0)
92
93 def forward(self, x: Tensor) -> Tensor:
94 return self._forward_impl(x)

Callers

nothing calls this directly

Calls 2

_make_layersFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected