def __init__(self, n_classes=6): super(SteerCNN, self).__init__() # the model is equivariant under rotations by 45 degrees, modelled by C8 self.r2_act = gspaces.Rot2dOnR2(N=4) # the input image is a scalar field, corresponding to the trivial representation input_type = nn_e2.FieldType(self.r2_act, 3 * [self.r2_act.trivial_repr]) # we store the input type for wrapping the images into a geometric tensor during the forward pass self.input_type = input_type # convolution 1 # first specify the output type of the convolutional layer # we choose 24 feature fields, each transforming under the regular representation of C8 out_type = nn_e2.FieldType(self.r2_act, 24 * [self.r2_act.regular_repr]) self.block1 = nn_e2.SequentialModule( nn_e2.R2Conv(input_type, out_type, kernel_size=7, padding=3, bias=False), nn_e2.InnerBatchNorm(out_type), nn_e2.ReLU(out_type, inplace=True)) self.pool1 = nn_e2.PointwiseAvgPool(out_type, 4) # convolution 2 # the old output type is the input type to the next layer in_type = self.block1.out_type # the output type of the second convolution layer are 48 regular feature fields of C8 #out_type = nn_e2.FieldType(self.r2_act, 48 * [self.r2_act.regular_repr]) self.block2 = nn_e2.SequentialModule( nn_e2.R2Conv(in_type, out_type, kernel_size=7, padding=3, bias=False), nn_e2.InnerBatchNorm(out_type), nn_e2.ReLU(out_type, inplace=True)) self.pool2 = nn_e2.SequentialModule( nn_e2.PointwiseAvgPoolAntialiased(out_type, sigma=0.66, stride=1, padding=0), nn_e2.PointwiseAvgPool(out_type, 4), nn_e2.GroupPooling(out_type)) # PointwiseAvgPoolAntialiased(out_type, sigma=0.66, stride=7) # number of output channels c = 24 * 13 * 13 #self.gpool.out_type.size # Fully Connected self.fully_net = torch.nn.Sequential( torch.nn.Linear(c, 64), torch.nn.BatchNorm1d(64), torch.nn.ELU(inplace=True), torch.nn.Linear(64, n_classes), )
def __init__(self, channel_in=3, n_classes=4, rot_n=4): super(SmallE2, self).__init__() r2_act = gspaces.Rot2dOnR2(N=rot_n) self.feat_type_in = nn.FieldType(r2_act, channel_in * [r2_act.trivial_repr]) feat_type_hid = nn.FieldType(r2_act, 8 * [r2_act.regular_repr]) feat_type_out = nn.FieldType(r2_act, 2 * [r2_act.regular_repr]) self.bn = nn.InnerBatchNorm(feat_type_hid) self.relu = nn.ReLU(feat_type_hid) self.convin = nn.R2Conv(self.feat_type_in, feat_type_hid, kernel_size=3) self.convhid = nn.R2Conv(feat_type_hid, feat_type_hid, kernel_size=3) self.convout = nn.R2Conv(feat_type_hid, feat_type_out, kernel_size=3) self.avgpool = nn.PointwiseAvgPool(feat_type_out, 3) self.invariant_map = nn.GroupPooling(feat_type_out) c = self.invariant_map.out_type.size self.lin_in = torch.nn.Linear(c, 64) self.elu = torch.nn.ELU() self.lin_out = torch.nn.Linear(64, n_classes)
def __init__(self): super(DenseFeatureExtractionModuleE2Inv, self).__init__() filters = np.array([32,32, 64,64, 128,128,128, 256,256,256, 512,512,512], dtype=np.int32)*2 # number of rotations to consider for rotation invariance N = 8 self.gspace = gspaces.Rot2dOnR2(N) self.input_type = enn.FieldType(self.gspace, [self.gspace.trivial_repr] * 3) ip_op_types = [ self.input_type, ] self.num_channels = 64 for filter_ in filters[:10]: ip_op_types.append(FIELD_TYPE['regular'](self.gspace, filter_, fixparams=False)) self.model = enn.SequentialModule(*[ conv3x3(ip_op_types[0], ip_op_types[1]), enn.ReLU(ip_op_types[1], inplace=True), conv3x3(ip_op_types[1], ip_op_types[2]), enn.ReLU(ip_op_types[2], inplace=True), enn.PointwiseMaxPool(ip_op_types[2], 2), conv3x3(ip_op_types[2], ip_op_types[3]), enn.ReLU(ip_op_types[3], inplace=True), conv3x3(ip_op_types[3], ip_op_types[4]), enn.ReLU(ip_op_types[4], inplace=True), enn.PointwiseMaxPool(ip_op_types[4], 2), conv3x3(ip_op_types[4], ip_op_types[5]), enn.ReLU(ip_op_types[5], inplace=True), conv3x3(ip_op_types[5], ip_op_types[6]), enn.ReLU(ip_op_types[6], inplace=True), conv3x3(ip_op_types[6], ip_op_types[7]), enn.ReLU(ip_op_types[7], inplace=True), enn.PointwiseAvgPool(ip_op_types[7], kernel_size=2, stride=1), conv5x5(ip_op_types[7], ip_op_types[8]), enn.ReLU(ip_op_types[8], inplace=True), conv5x5(ip_op_types[8], ip_op_types[9]), enn.ReLU(ip_op_types[9], inplace=True), conv5x5(ip_op_types[9], ip_op_types[10]), enn.ReLU(ip_op_types[10], inplace=True), # enn.PointwiseMaxPool(ip_op_types[7], 2), # conv3x3(ip_op_types[7], ip_op_types[8]), # enn.ReLU(ip_op_types[8], inplace=True), # conv3x3(ip_op_types[8], ip_op_types[9]), # enn.ReLU(ip_op_types[9], inplace=True), # conv3x3(ip_op_types[9], ip_op_types[10]), # enn.ReLU(ip_op_types[10], inplace=True), enn.GroupPooling(ip_op_types[10]) ])
def __init__(self, in_type, out_type, gspace): super(TransitionBlock, self).__init__() self.gspace = gspace self.in_type = FIELD_TYPE["regular"](self.gspace, in_type, fixparams=False) self.out_type = FIELD_TYPE["regular"](self.gspace, out_type, fixparams=False) self.bn1 = enn.InnerBatchNorm(self.in_type) self.relu1 = enn.ReLU(self.in_type,inplace=True) self.conv1 = conv1x1(self.in_type,self.out_type) self.avgpool = enn.PointwiseAvgPool(self.out_type, kernel_size=2)
def ennAvgPool(inplanes, kernel_size=1, stride=None, padding=0, ceil_mode=False): in_type = FIELD_TYPE['regular'](gspace, inplanes) return enn.PointwiseAvgPool(in_type, kernel_size, stride=stride, padding=padding, ceil_mode=ceil_mode)
def __init__(self, n_classes=10): super(C8SteerableCNN, self).__init__() # the model is equivariant under rotations by 45 degrees, modelled by C8 self.r2_act = gspaces.Rot2dOnR2(N=8) # the input image is a scalar field, corresponding to the trivial representation in_type = nn.FieldType(self.r2_act, [self.r2_act.trivial_repr]) # we store the input type for wrapping the images into a geometric tensor during the forward pass self.input_type = in_type # convolution 1 # first specify the output type of the convolutional layer # we choose 16 feature fields, each transforming under the regular representation of C8 out_type = nn.FieldType(self.r2_act, 24 * [self.r2_act.regular_repr]) self.block1 = nn.SequentialModule( # nn.MaskModule(in_type, 29, margin=1), nn.R2Conv(in_type, out_type, kernel_size=7, padding=1, bias=False), nn.InnerBatchNorm(out_type), nn.ReLU(out_type, inplace=True)) # convolution 2 # the old output type is the input type to the next layer in_type = self.block1.out_type # the output type of the second convolution layer are 32 regular feature fields of C8 out_type = nn.FieldType(self.r2_act, 48 * [self.r2_act.regular_repr]) self.block2 = nn.SequentialModule( nn.R2Conv(in_type, out_type, kernel_size=5, padding=2, bias=False), nn.InnerBatchNorm(out_type), nn.ReLU(out_type, inplace=True)) self.pool1 = nn.SequentialModule( nn.PointwiseAvgPoolAntialiased(out_type, sigma=0.66, stride=2)) # convolution 3 # the old output type is the input type to the next layer in_type = self.block2.out_type # the output type of the third convolution layer are 32 regular feature fields of C8 out_type = nn.FieldType(self.r2_act, 48 * [self.r2_act.regular_repr]) self.block3 = nn.SequentialModule( nn.R2Conv(in_type, out_type, kernel_size=5, padding=2, bias=False), nn.InnerBatchNorm(out_type), nn.ReLU(out_type, inplace=True)) # convolution 4 # the old output type is the input type to the next layer in_type = self.block3.out_type # the output type of the fourth convolution layer are 64 regular feature fields of C8 out_type = nn.FieldType(self.r2_act, 96 * [self.r2_act.regular_repr]) self.block4 = nn.SequentialModule( nn.R2Conv(in_type, out_type, kernel_size=5, padding=2, bias=False), nn.InnerBatchNorm(out_type), nn.ReLU(out_type, inplace=True)) self.pool2 = nn.SequentialModule( nn.PointwiseAvgPoolAntialiased(out_type, sigma=0.66, stride=2)) # convolution 5 # the old output type is the input type to the next layer in_type = self.block4.out_type # the output type of the fifth convolution layer are 64 regular feature fields of C8 out_type = nn.FieldType(self.r2_act, 96 * [self.r2_act.regular_repr]) self.block5 = nn.SequentialModule( nn.R2Conv(in_type, out_type, kernel_size=5, padding=2, bias=False), nn.InnerBatchNorm(out_type), nn.ReLU(out_type, inplace=True)) # convolution 6 # the old output type is the input type to the next layer in_type = self.block5.out_type # the output type of the sixth convolution layer are 64 regular feature fields of C8 out_type = nn.FieldType(self.r2_act, 64 * [self.r2_act.regular_repr]) self.block6 = nn.SequentialModule( nn.R2Conv(in_type, out_type, kernel_size=5, padding=1, bias=False), nn.InnerBatchNorm(out_type), nn.ReLU(out_type, inplace=True)) self.pool3 = nn.PointwiseAvgPool(out_type, kernel_size=4) self.gpool = nn.GroupPooling(out_type) # number of output channels c = self.gpool.out_type.size # Fully Connected self.fully_net = torch.nn.Sequential( torch.nn.Linear(c, 64), torch.nn.BatchNorm1d(64), torch.nn.ELU(inplace=True), torch.nn.Linear(64, n_classes), )