def __init__(self, outputs, inputs): super(BBBLeNet, self).__init__() self.conv1 = BBBConv2d(inputs, 6, 5, stride=1) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = BBBConv2d(6, 16, 5, stride=1) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.flatten = FlattenLayer(5 * 5 * 16) self.fc1 = BBBLinearFactorial(5 * 5 * 16, 120) self.soft3 = nn.Softplus() self.fc2 = BBBLinearFactorial(120, 84) self.soft4 = nn.Softplus() self.fc3 = BBBLinearFactorial(84, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.flatten, self.fc1, self.soft3, self.fc2, self.soft4, self.fc3 ] self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs): super(BBB3Conv3FC, self).__init__() self.conv1 = BBBConv2d(inputs, 32, 5, stride=1, padding=2) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv2 = BBBConv2d(32, 64, 5, stride=1, padding=2) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv3 = BBBConv2d(64, 128, 5, stride=1, padding=1) self.soft3 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=3, stride=2) self.flatten = FlattenLayer(2 * 2 * 128) self.fc1 = BBBLinearFactorial(2 * 2 * 128, 1000) self.soft5 = nn.Softplus() self.fc2 = BBBLinearFactorial(1000, 1000) self.soft6 = nn.Softplus() self.fc3 = BBBLinearFactorial(1000, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.conv3, self.soft3, self.pool3, self.flatten, self.fc1, self.soft5, self.fc2, self.soft6, self.fc3 ] self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs,): super(_ClassifierD, self).__init__() self.outputs = outputs #due to the convlayer change have to assume the logvar initial value. self.q_logvar_init = 0.05 self.p_logvar_init = math.log(0.05) self.conv1 = BBBConv2d(self.q_logvar_init, self.p_logvar_init,inputs,6, 5, stride=1) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = BBBConv2d(self.q_logvar_init, self.p_logvar_init,6, 16, 5, stride=1) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.flatten = FlattenLayer(5 * 5 * 16) self.fc1 = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init,5 * 5 * 16, 120) self.soft3 = nn.Softplus() self.fc2 = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init,120, 84) self.soft4 = nn.Softplus() #self.fc3 = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init,84, outputs) self.fcA = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init,84, 1) self.fcB = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init,84, 1) layers = [self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.flatten, self.fc1, self.soft3, self.fc2, self.soft4] #not sure if this is right, test drive. self.prob = nn.Sigmoid() if outputs == 1: layers.append(self.prob) self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs): super(_BayesianAlexNetD, self).__init__() self.q_logvar_init = 0.05 self.p_logvar_init = math.log(0.05) self.classifier = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init, 1* 1 * 128, outputs) self.conv1 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, inputs, 64, kernel_size=11, stride=4, padding=5) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 64, 192, kernel_size=5, padding=2) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 192, 384, kernel_size=3, padding=1) self.soft3 = nn.Softplus() self.conv4 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 384, 256, kernel_size=3, padding=1) self.soft4 = nn.Softplus() self.conv5 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 256, 128, kernel_size=3, padding=1) self.soft5 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2) # self.flatten = FlattenLayer(1 * 1 * 128) # self.fc1 = BBBLinearFactorial(q_logvar_init, N, p_logvar_init, 1* 1 * 128, outputs) layers = [self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.conv3, self.soft3, self.conv4, self.soft4, self.conv5, self.soft5, self.pool3] self.layers = nn.ModuleList(layers)
def __init__(self, in_planes, planes, stride=1): super(Bottleneck, self).__init__() self.conv1 = BBBConv2d(in_planes, planes, kernel_size=1, bias=True) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = BBBConv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=True) self.bn2 = nn.BatchNorm2d(planes) self.conv3 = BBBConv2d(planes, self.expansion * planes, kernel_size=1, bias=True) self.bn3 = nn.BatchNorm2d(self.expansion * planes) self.shortcut = nn.Sequential() if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential( BBBConv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias=True), nn.BatchNorm2d(self.expansion * planes))
def __init__(self, outputs, inputs): super(BBBAlexNet_5Conv1FC, self).__init__() self.conv1 = BBBConv2d(inputs, 64, kernel_size=11, stride=4, padding=5) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = BBBConv2d(64, 192, kernel_size=5, padding=2) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3 = BBBConv2d(192, 384, kernel_size=3, padding=1) self.soft3 = nn.Softplus() self.conv4 = BBBConv2d(384, 256, kernel_size=3, padding=1) self.soft4 = nn.Softplus() self.conv5 = BBBConv2d(256, 256, kernel_size=3, padding=1) self.soft5 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2) self.flatten = FlattenLayer(1 * 1 * 256) self.fc1 = BBBLinearFactorial(1 * 1 * 256, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.conv3, self.soft3, self.conv4, self.soft4, self.conv5, self.soft5, self.pool3, self.flatten, self.fc1 ] self.layers = nn.ModuleList(layers)
def __init__( self, noize, ): super(_BayesianNetG, self).__init__() #due to the convlayer change have to assume the logvar initial value. self.q_logvar_init = 0.05 self.p_logvar_init = math.log(0.05) self.conv1 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, noize, 128, kernel_size=3, stride=1, padding=1) self.soft = nn.Softplus() self.conv2 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 128, 64, kernel_size=3, stride=1, padding=1) self.conv3 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 64, 32, kernel_size=3, stride=1, padding=1) self.conv4 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 32, 16, kernel_size=3, stride=1, padding=1) self.conv5 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, 16, 3, kernel_size=3, stride=1, padding=1) layers = [ self.conv1, self.soft, self.conv2, self.soft, self.conv3, self.soft, self.conv4, self.soft, self.conv5, self.soft ] self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs): super(BBBAlexNet, self).__init__() # self.conv1 = BBBConv2d(inputs, 64, kernel_size=11, stride=4, padding=5) # self.soft1 = nn.Softplus() # self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) # # self.conv2 = BBBConv2d(64, 192, kernel_size=5, padding=2) # self.soft2 = nn.Softplus() # self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) # # self.conv3 = BBBConv2d(192, 384, kernel_size=3, padding=1) # self.soft3 = nn.Softplus() # # self.conv4 = BBBConv2d(384, 256, kernel_size=3, padding=1) # self.soft4 = nn.Softplus() # # self.conv5 = BBBConv2d(256, 128, kernel_size=3, padding=1) # self.soft5 = nn.Softplus() # self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2) # # self.flatten = FlattenLayer(1 * 1 * 128) # self.fc1 = BBBLinearFactorial(1* 1 * 128, outputs) self.conv1 = BBBConv2d(inputs, 96, kernel_size=11, stride=4) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv2 = BBBConv2d(96, 256, kernel_size=5, stride=1, padding=2) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv3 = BBBConv2d(256, 384, kernel_size=3, stride=1, padding=1) self.soft3 = nn.Softplus() self.conv4 = BBBConv2d(384, 384, kernel_size=3, stride=1, padding=1) self.soft4 = nn.Softplus() self.conv5 = BBBConv2d(384, 256, kernel_size=3, stride=1, padding=1) self.soft5 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=3, stride=2) self.flatten = FlattenLayer(6 * 6 * 256) self.fc1 = BBBLinearFactorial(6 * 6 * 256, 4096) self.dropout1 = nn.Dropout(p=0.5) self.fc2 = BBBLinearFactorial(4096, 4096) self.dropout2 = nn.Dropout(p=0.5) self.fc3 = BBBLinearFactorial(4096, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.conv3, self.soft3, self.conv4, self.soft4, self.conv5, self.soft5, self.pool3, self.flatten, self.fc1, self.dropout1, self.fc2, self.dropout2, self.fc3 ] self.layers = nn.ModuleList(layers)
def conv3x3(in_planes, out_planes, stride=1): return BBBConv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True)
def __init__(self, upscale_factor): super(BBBNet, self).__init__() self.relu = nn.ReLU() self.conv1 = BBBConv2d(1, 64, (5, 5), (1, 1), (2, 2)) self.conv2 = BBBConv2d(64, 64, (3, 3), (1, 1), (1, 1)) self.conv3 = BBBConv2d(64, 32, (3, 3), (1, 1), (1, 1)) self.conv4 = BBBConv2d(32, upscale_factor**2, (3, 3), (1, 1), (1, 1)) self.pixel_shuffle = nn.PixelShuffle(upscale_factor) layers = [ self.conv1, self.relu, self.conv2, self.relu, self.conv3, self.relu, self.conv4, self.relu, self.pixel_shuffle ] self.layers = nn.ModuleList(layers)
def conv1x1(in_planes, out_planes, stride=1): """1x1 convolution""" q_logvar_init = 0.05 p_logvar_init = math.log(0.05) return BBBConv2d(q_logvar_init, p_logvar_init, in_planes, out_planes, kernel_size=1, stride=stride, bias=False)
def __init__(self, outputs, inputs): super(BBB4Conv3FC, self).__init__() self.conv1 = BBBConv2d(inputs, 32, kernel_size=5, stride=1, padding=0) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv2 = BBBConv2d(32, 64, kernel_size=5, stride=1, padding=0) self.soft2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv3 = BBBConv2d(64, 128, kernel_size=5, stride=1, padding=0) self.soft3 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=3, stride=2) self.conv4 = BBBConv2d(128, 256, kernel_size=5, stride=1, padding=0) self.soft4 = nn.Softplus() self.pool4 = nn.MaxPool2d(kernel_size=3, stride=2) # self.conv5 = BBBConv2d(256, 512, kernel_size=5, stride=1, padding=0) # self.soft5 = nn.Softplus() # self.pool5 = nn.MaxPool2d(kernel_size=3, stride=2) self.flatten = FlattenLayer(3 * 3 * 256) self.fc1 = BBBLinearFactorial(3 * 3 * 256, 1000) self.soft6 = nn.Softplus() self.fc2 = BBBLinearFactorial(1000, 1000) self.soft7 = nn.Softplus() self.fc3 = BBBLinearFactorial(1000, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.pool2, self.conv3, self.soft3, self.pool3, self.conv4, self.soft4, self.pool4, self.flatten, self.fc1, self.soft6, self.fc2, self.soft7, self.fc3 ] self.layers = nn.ModuleList(layers)
def conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1): """3x3 convolution with padding""" q_logvar_init = 0.05 p_logvar_init = math.log(0.05) return BBBConv2d(q_logvar_init, p_logvar_init, in_planes, out_planes, kernel_size=3, stride=stride, padding=dilation, groups=groups, bias=False, dilation=dilation)
def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = conv3x3(in_planes, planes, stride) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = conv3x3(planes, planes) self.bn2 = nn.BatchNorm2d(planes) self.shortcut = nn.Sequential() if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential( BBBConv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias=True), nn.BatchNorm2d(self.expansion * planes))
def __init__(self, outputs, inputs): super(BBBAlexNet_6Conv3FC, self).__init__() self.conv1 = BBBConv2d(inputs, 32, kernel_size=3, stride=1, padding=1) self.norm1 = nn.BatchNorm2d(32) self.soft1 = nn.Softplus() self.conv2 = BBBConv2d(32, 64, kernel_size=3, stride=1, padding=1) self.soft2 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3 = BBBConv2d(64, 128, kernel_size=3, stride=1, padding=1) self.norm2 = nn.BatchNorm2d(128) self.soft3 = nn.Softplus() self.conv4 = BBBConv2d(128, 128, kernel_size=3, stride=1, padding=1) self.soft4 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.dropout1 = nn.Dropout(p=0.05) self.conv5 = BBBConv2d(128, 256, kernel_size=3, stride=1, padding=1) self.norm3 = nn.BatchNorm2d(256) self.soft5 = nn.Softplus() self.conv6 = BBBConv2d(256, 256, kernel_size=3, stride=1, padding=1) self.soft6 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2) self.dropout2 = nn.Dropout(p=0.1) self.flatten = FlattenLayer(4 * 4 * 256) self.fc1 = BBBLinearFactorial(4 * 4 * 256, 1024) self.soft7 = nn.Softplus() self.fc2 = BBBLinearFactorial(1024, 512) self.soft8 = nn.Softplus() self.dropout3 = nn.Dropout(p=0.1) self.fc3 = BBBLinearFactorial(512, outputs) layers = [ self.conv1, self.soft1, self.conv2, self.soft2, self.pool1, self.conv3, self.soft3, self.conv4, self.soft4, self.pool2, self.conv5, self.soft5, self.conv6, self.soft6, self.pool3, self.flatten, self.fc1, self.soft7, self.fc2, self.soft8, self.dropout3, self.fc3 ] self.layers = nn.ModuleList(layers)
def __init__(self, block, layers, input_channels, num_classes=10, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None): super(ResNet, self).__init__() if norm_layer is None: norm_layer = nn.BatchNorm2d self._norm_layer = norm_layer self.inplanes = 64 self.dilation = 1 self.q_logvar_init = 0.05 self.p_logvar_init = math.log(0.05) if replace_stride_with_dilation is None: # each element in the tuple indicates if we should replace # the 2x2 stride with a dilated convolution instead replace_stride_with_dilation = [False, False, False] if len(replace_stride_with_dilation) != 3: raise ValueError("replace_stride_with_dilation should be None " "or a 3-element tuple, got {}".format( replace_stride_with_dilation)) self.groups = groups self.base_width = width_per_group self.conv1 = BBBConv2d(self.q_logvar_init, self.p_logvar_init, input_channels, self.inplanes, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = norm_layer(self.inplanes) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.layer1 = self._make_layer(block, 64, layers[0]) self.layer2 = self._make_layer(block, 128, layers[1], stride=2, dilate=replace_stride_with_dilation[0]) self.layer3 = self._make_layer(block, 256, layers[2], stride=2, dilate=replace_stride_with_dilation[1]) self.layer4 = self._make_layer(block, 512, layers[3], stride=2, dilate=replace_stride_with_dilation[2]) self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) self.drop = nn.Dropout(p=.5) self.classifier = BBBLinearFactorial(self.q_logvar_init, self.p_logvar_init, 512 * block.expansion, num_classes, flow=False) print(block.expansion) layers2 = [ self.conv1, self.bn1, self.relu, self.maxpool, self.layer1, self.layer2, self.layer3, self.layer4, self.avgpool ] self.layers2 = nn.ModuleList(layers2) for m in self.modules(): if isinstance(m, BBBConv2d): m.reset_parameters() elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)): nn.init.constant_(m.weight, 1) nn.init.constant_(m.bias, 0) # Zero-initialize the last BN in each residual branch, # so that the residual branch starts with zeros, and each residual block behaves like an identity. # This improves the model by 0.2~0.3% according to https://arxiv.org/abs/1706.02677 if zero_init_residual: for m in self.modules(): if isinstance(m, Bottleneck): nn.init.constant_(m.bn3.weight, 0) elif isinstance(m, BasicBlock): nn.init.constant_(m.bn2.weight, 0)
def __init__(self, outputs, inputs): super(BBBCNN1, self).__init__() self.conv1 = BBBConv2d(inputs, 92, 3, stride=1) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv2 = BBBConv2d(92, 384, 1, stride=1) self.soft2 = nn.Softplus() self.conv3 = BBBConv2d(384, 384, 2, stride=1) self.soft3 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv4 = BBBConv2d(384, 640, 2, stride=1) self.soft4 = nn.Softplus() self.conv5 = BBBConv2d(640, 640, 2, stride=1) self.soft5 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv6 = BBBConv2d(640, 640, 1, stride=1) self.soft6 = nn.Softplus() self.conv7 = BBBConv2d(640, 768, 2, stride=1) self.soft7 = nn.Softplus() self.pool4 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv8 = BBBConv2d(768, 768, 2, stride=1) self.soft8 = nn.Softplus() self.conv9 = BBBConv2d(768, 768, 2, stride=1) self.soft9 = nn.Softplus() self.pool5 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv10 = BBBConv2d(768, 768, 1, stride=1) self.soft10 = nn.Softplus() self.conv11 = BBBConv2d(768, 640, 2, stride=1) self.soft11 = nn.Softplus() self.conv12 = BBBConv2d(640, 384, 2, stride=1) self.soft12 = nn.Softplus() self.pool6 = nn.MaxPool2d(kernel_size=2, stride=2) self.flatten = FlattenLayer(8 * 8 * 384) self.fc1 = BBBLinearFactorial(8 * 8 * 384, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.conv3, self.soft3, self.pool2, self.conv4, self.soft4, self.conv5, self.soft5, self.pool3, self.conv6, self.soft6, self.conv7, self.soft7, self.pool4, self.conv8, self.soft8, self.conv9, self.soft9, self.pool5, self.conv10, self.soft10, self.conv11, self.soft11, self.conv12, self.soft12, self.pool6, self.flatten, self.fc1 ] self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs): super(BBBSqueezeNet, self).__init__() self.conv1 = BBBConv2d(inputs, 64, kernel_size=3, stride=2) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True) # Fire module 1 self.squeeze1 = BBBConv2d(64, 16, kernel_size=1) self.squeeze_activation1 = nn.Softplus() self.expand3x3_1 = BBBConv2d(16, 128, kernel_size=3, padding=1) self.expand3x3_activation1 = nn.Softplus() # Fire module 2 self.squeeze2 = BBBConv2d(128, 16, kernel_size=1) self.squeeze_activation2 = nn.Softplus() self.expand3x3_2 = BBBConv2d(16, 128, kernel_size=3, padding=1) self.expand3x3_activation2 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True) # Fire module 3 self.squeeze3 = BBBConv2d(128, 32, kernel_size=1) self.squeeze_activation3 = nn.Softplus() self.expand3x3_3 = BBBConv2d(32, 256, kernel_size=3, padding=1) self.expand3x3_activation3 = nn.Softplus() # Fire module 4 self.squeeze4 = BBBConv2d(256, 32, kernel_size=1) self.squeeze_activation4 = nn.Softplus() self.expand3x3_4 = BBBConv2d(32, 256, kernel_size=3, padding=1) self.expand3x3_activation4 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True) # Fire module 5 self.squeeze5 = BBBConv2d(256, 48, kernel_size=1) self.squeeze_activation5 = nn.Softplus() self.expand3x3_5 = BBBConv2d(48, 384, kernel_size=3, padding=1) self.expand3x3_activation5 = nn.Softplus() # Fire module 6 self.squeeze6 = BBBConv2d(384, 48, kernel_size=1) self.squeeze_activation6 = nn.Softplus() self.expand3x3_6 = BBBConv2d(48, 384, kernel_size=3, padding=1) self.expand3x3_activation6 = nn.Softplus() # Fire module 7 self.squeeze7 = BBBConv2d(384, 64, kernel_size=1) self.squeeze_activation7 = nn.Softplus() self.expand3x3_7 = BBBConv2d(64, 512, kernel_size=3, padding=1) self.expand3x3_activation7 = nn.Softplus() # Fire module 8 self.squeeze8 = BBBConv2d(512, 64, kernel_size=1) self.squeeze_activation8 = nn.Softplus() self.expand3x3_8 = BBBConv2d(64, 512, kernel_size=3, padding=1) self.expand3x3_activation8 = nn.Softplus() self.drop1 = nn.Dropout(p=0.5) self.conv2 = BBBConv2d(512, outputs, kernel_size=1) self.soft2 = nn.Softplus() self.flatten = FlattenLayer(13 * 13 * 100) self.fc1 = BBBLinearFactorial(13 * 13 * 100, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.squeeze1, self.squeeze_activation1, self.expand3x3_1, self.expand3x3_activation1, self.squeeze2, self.squeeze_activation2, self.expand3x3_2, self.expand3x3_activation2, self.pool2, self.squeeze3, self.squeeze_activation3, self.expand3x3_3, self.expand3x3_activation3, self.squeeze4, self.squeeze_activation4, self.expand3x3_4, self.expand3x3_activation4, self.pool3, self.squeeze5, self.squeeze_activation5, self.expand3x3_5, self.expand3x3_activation5, self.squeeze6, self.squeeze_activation6, self.expand3x3_6, self.expand3x3_activation6, self.squeeze7, self.squeeze_activation7, self.expand3x3_7, self.expand3x3_activation7, self.squeeze8, self.squeeze_activation8, self.expand3x3_8, self.expand3x3_activation8, self.drop1, self.conv2, self.soft2, self.flatten, self.fc1 ] self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs): super(BBBELUN2, self).__init__() self.conv1 = BBBConv2d(inputs, 96, 6, stride=1) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = BBBConv2d(96, 512, 3, stride=1) self.soft2 = nn.Softplus() self.conv3 = BBBConv2d(512, 512, 3, stride=1) self.soft3 = nn.Softplus() self.conv4 = BBBConv2d(512, 512, 3, stride=1) self.soft4 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv5 = BBBConv2d(512, 768, 3, stride=1) self.soft5 = nn.Softplus() self.conv6 = BBBConv2d(768, 768, 3, stride=1) self.soft6 = nn.Softplus() self.conv7 = BBBConv2d(768, 768, 2, stride=1) self.soft7 = nn.Softplus() self.conv8 = BBBConv2d(768, 768, 2, stride=1) self.soft8 = nn.Softplus() self.conv9 = BBBConv2d(768, 768, 1, stride=1) self.soft9 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv10 = BBBConv2d(768, 1024, 3, stride=1) self.soft10 = nn.Softplus() self.conv11 = BBBConv2d(1024, 1024, 3, stride=1) self.soft11 = nn.Softplus() self.conv12 = BBBConv2d(1024, 1024, 3, stride=1) self.soft12 = nn.Softplus() self.pool4 = nn.MaxPool2d(kernel_size=2, stride=2) self.flatten = FlattenLayer(8 * 8 * 1024) self.fc1 = BBBLinearFactorial(8 * 8 * 1024, 4096) self.soft13 = nn.Softplus() self.fc2 = BBBLinearFactorial(4096, 4096) self.soft14 = nn.Softplus() self.fc3 = BBBLinearFactorial(4096, outputs) layers = [self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.conv3, self.soft3, self.conv4, self.soft4, self.pool2, self.conv5, self.soft5, self.conv6, self.soft6, self.conv7, self.soft7, self.conv8, self.soft8, self.conv9, self.soft9, self.pool3, self.conv10, self.soft10, self.conv11, self.soft11, self.conv12, self.soft12, self.pool4, self.flatten, self.fc1, self.soft13, self.fc2, self.soft14, self.fc3] self.layers = nn.ModuleList(layers)
def __init__(self, outputs, inputs): super(BBBELUN1, self).__init__() self.conv1 = BBBConv2d(inputs, 384, 3, stride=1) self.soft1 = nn.Softplus() self.pool1 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv2 = BBBConv2d(384, 384, 1, stride=1) self.soft2 = nn.Softplus() self.conv3 = BBBConv2d(384, 384, 2, stride=1) self.soft3 = nn.Softplus() self.conv4 = BBBConv2d(384, 640, 2, stride=1) self.soft4 = nn.Softplus() self.conv5 = BBBConv2d(640, 640, 2, stride=1) self.soft5 = nn.Softplus() self.pool2 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv6 = BBBConv2d(640, 640, 1, stride=1) self.soft6 = nn.Softplus() self.conv7 = BBBConv2d(640, 768, 2, stride=1) self.soft7 = nn.Softplus() self.conv8 = BBBConv2d(768, 768, 2, stride=1) self.soft8 = nn.Softplus() self.conv9 = BBBConv2d(768, 768, 2, stride=1) self.soft9 = nn.Softplus() self.pool3 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv10 = BBBConv2d(768, 768, 1, stride=1) self.soft10 = nn.Softplus() self.conv11 = BBBConv2d(768, 896, 2, stride=1) self.soft11 = nn.Softplus() self.conv12 = BBBConv2d(896, 896, 2, stride=1) self.soft12 = nn.Softplus() self.pool4 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv13 = BBBConv2d(896, 896, 3, stride=1) self.soft13 = nn.Softplus() self.conv14 = BBBConv2d(896, 1024, 2, stride=1) self.soft14 = nn.Softplus() self.conv15 = BBBConv2d(1024, 1024, 2, stride=1) self.soft15 = nn.Softplus() self.pool5 = nn.MaxPool2d(kernel_size=2, stride=1) self.conv16 = BBBConv2d(1024, 1024, 1, stride=1) self.soft16 = nn.Softplus() self.conv17 = BBBConv2d(1024, 1152, 2, stride=1) self.soft17 = nn.Softplus() self.pool6 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv18 = BBBConv2d(1152, 1152, 2, stride=1) self.soft18 = nn.Softplus() self.pool7 = nn.MaxPool2d(kernel_size=2, stride=2) self.flatten = FlattenLayer(2 * 2 * 1152) self.fc1 = BBBLinearFactorial(2 * 2 * 1152, outputs) layers = [ self.conv1, self.soft1, self.pool1, self.conv2, self.soft2, self.conv3, self.soft3, self.conv4, self.soft4, self.conv5, self.soft5, self.pool2, self.conv6, self.soft6, self.conv7, self.soft7, self.conv8, self.soft8, self.conv9, self.soft9, self.pool3, self.conv10, self.soft10, self.conv11, self.soft11, self.conv12, self.soft12, self.pool4, self.conv13, self.soft13, self.conv14, self.soft14, self.conv15, self.soft15, self.pool5, self.conv16, self.soft16, self.conv17, self.soft17, self.pool6, self.conv18, self.soft18, self.pool7, self.flatten, self.fc1 ] self.layers = nn.ModuleList(layers)