public SqueezeNet(string version = "1_0", int num_classes = 1000) { this.num_classes = num_classes; if (version == "1_0") { this.features = new nn.Sequential( new nn.Conv2d(3, 96, kernel_size: 7, stride: 2), new nn.ReLU(), new nn.MaxPool2d(kernel_size: 3, stride: 2), new Fire(96, 16, 64, 64), new Fire(128, 16, 64, 64), new Fire(128, 32, 128, 128), new nn.MaxPool2d(kernel_size: 3, stride: 2), new Fire(256, 32, 128, 128), new Fire(256, 48, 192, 192), new Fire(384, 48, 192, 192), new Fire(384, 64, 256, 256), new nn.MaxPool2d(kernel_size: 3, stride: 2), new Fire(512, 64, 256, 256) ); } else { if (version == "1_1") { this.features = new nn.Sequential( new nn.Conv2d(3, 64, kernel_size: 3, stride: 2), new nn.ReLU(), new nn.MaxPool2d(kernel_size: 3, stride: 2), new Fire(64, 16, 64, 64), new Fire(128, 16, 64, 64), new nn.MaxPool2d(kernel_size: 3, stride: 2), new Fire(128, 32, 128, 128), new Fire(256, 32, 128, 128), new nn.MaxPool2d(kernel_size: 3, stride: 2), new Fire(256, 48, 192, 192), new Fire(384, 48, 192, 192), new Fire(384, 64, 256, 256), new Fire(512, 64, 256, 256) ); } else { throw new torch.TorchException(string.Format("TorchException: Unsupported SqueezeNet version {0}: 1_0 or 1_1 expected.", version)); } } var final_conv = new nn.Conv2d(512, this.num_classes, kernel_size: 1); this.classifier = new nn.Sequential( new nn.Dropout(p: 0.5), final_conv, new nn.ReLU(), new nn.AvgPool2d(13, 13) ); }
public Fire(int inplanes, int squeeze_planes, int expand1x1_planes, int expand3x3_planes) { this.inplanes = inplanes; this.squeeze = new nn.Conv2d(inplanes, squeeze_planes, kernel_size: 1); this.squeeze_activation = new nn.ReLU(); this.expand1x1 = new nn.Conv2d(squeeze_planes, expand1x1_planes, kernel_size: 1); this.expand1x1_activation = new nn.ReLU(); this.expand3x3 = new nn.Conv2d(squeeze_planes, expand3x3_planes, kernel_size: 3, padding: 1); this.expand3x3_activation = new nn.ReLU(); }