def p_net(): return Sequential(Conv2d((3, 3), 10, strides=1, auto_pad=False, use_bias=True, name='conv1'), PRelu(num_parameters=1), MaxPool2d((2, 2), strides=2, auto_pad=False), Conv2d((3, 3), 16, strides=1, auto_pad=False, use_bias=True, name='conv2'), PRelu(num_parameters=1), Conv2d((3, 3), 32, strides=1, auto_pad=False, use_bias=True, name='conv3'), PRelu(num_parameters=1), ModuleDict( { 'conv4_1': Conv2d((1, 1), 1, strides=1, auto_pad=False, use_bias=True, activation='sigmoid', name='conv4_1'), 'conv4_2': Conv2d((1, 1), 4, strides=1, auto_pad=False, use_bias=True, name='conv4_2'), 'conv4_3': Conv2d((1, 1), 10, strides=1, auto_pad=False, use_bias=True, name='conv4_3') }, is_multicasting=True), name='pnet')
def o_net(): return Sequential(Conv2d((3, 3), 32, strides=1, auto_pad=False, use_bias=True, name='conv1'), PRelu(num_parameters=1), MaxPool2d((3, 3), strides=2, auto_pad=False), Conv2d((3, 3), 64, strides=1, auto_pad=False, use_bias=True, name='conv2'), PRelu(num_parameters=1), MaxPool2d((3, 3), strides=2, auto_pad=False), Conv2d((3, 3), 64, strides=1, auto_pad=False, use_bias=True, name='conv3'), PRelu(num_parameters=1), MaxPool2d((2, 2), strides=2, auto_pad=False), Conv2d((2, 2), 128, strides=1, auto_pad=False, use_bias=True, name='conv4'), PRelu(num_parameters=1), Flatten(), Dense(256, activation=None, use_bias=True, name='conv5'), PRelu(num_parameters=1), Combine( Dense(1, activation='sigmoid', use_bias=True, name='conv6_1'), Dense(4, activation=None, use_bias=True, name='conv6_2'), Dense(10, activation=None, use_bias=True, name='conv6_3')), name='onet')
def BottleNeck_IR_SE(num_filters, strides, keep_filter=True): blocks = OrderedDict() blocks['res_layer'] = Sequential(BatchNorm2d(), Conv2d_Block( (3, 3), num_filters=num_filters, strides=1, auto_pad=True, use_bias=False, activation=PRelu(num_filters)), Conv2d_Block((3, 3), num_filters, strides=strides, use_bias=False, activation=None, normalization='batch'), SqueezeExcite(num_filters // 16, num_filters), name='res_layer') if keep_filter: blocks['shortcut_layer'] = MaxPool2d(1, strides=strides, name='shortcut_layer') else: blocks['shortcut_layer'] = Conv2d_Block((1, 1), num_filters, strides=strides, use_bias=False, activation=None, normalization='batch', name='shortcut_layer') return ShortCut2d(blocks, mode='add')
def p_net(): return Sequential(Conv2d((3, 3), 10, strides=1, auto_pad=False, use_bias=True, name='conv1'), PRelu(num_parameters=1), MaxPool2d((2, 2), strides=2, auto_pad=False), Conv2d((3, 3), 16, strides=1, auto_pad=False, use_bias=True, name='conv2'), PRelu(num_parameters=1), Conv2d((3, 3), 32, strides=1, auto_pad=False, use_bias=True, name='conv3'), PRelu(num_parameters=1), Combine( Conv2d((1, 1), 1, strides=1, auto_pad=False, use_bias=True, activation='sigmoid', name='conv4_1'), Conv2d((1, 1), 4, strides=1, auto_pad=False, use_bias=True, name='conv4_2'), Conv2d((1, 1), 10, strides=1, auto_pad=False, use_bias=True, name='conv4_3')), name='pnet')
def r_net(): return Sequential( Conv2d((3, 3), 28, strides=1, auto_pad=False, use_bias=True, name='conv1'), PRelu(num_parameters=1), MaxPool2d((3, 3), strides=2, auto_pad=False), Conv2d((3, 3), 48, strides=1, auto_pad=False, use_bias=True, name='conv2'), PRelu(num_parameters=1), MaxPool2d((3, 3), strides=2, auto_pad=False), Conv2d((2, 2), 64, strides=1, auto_pad=False, use_bias=True, name='conv3'), PRelu(num_parameters=1), Flatten(), Dense(128, activation=None, use_bias=True, name='conv4'), PRelu(num_parameters=1), ModuleDict( { 'conv5_1': Dense(1, activation='sigmoid', use_bias=True, name='conv5_1'), 'conv5_2': Dense(4, activation=None, use_bias=True, name='conv5_2'), 'conv5_3': Dense(10, activation=None, use_bias=True, name='conv5_3') }, is_multicasting=True), name='rnet')
def SEResNet_IR(include_top=True, num_layers=50, Bottleneck=BottleNeck_IR_SE, drop_ratio=0.4, feature_dim=128, input_shape=(3, 112, 112)): blocks = OrderedDict() blocks['input_layer'] = Conv2d_Block((3, 3), 64, strides=1, auto_pad=True, use_bias=False, activation=PRelu(64), normalization='batch', name='input_layer') blocks['body'] = Sequential( get_block(Bottleneck, out_channel=64, num_units=3, keep_filter=True) + get_block(Bottleneck, out_channel=128, num_units=4, keep_filter=False) + get_block( Bottleneck, out_channel=256, num_units=14, keep_filter=False) + get_block(Bottleneck, out_channel=512, num_units=3, keep_filter=False)) blocks['output_layer'] = Sequential(BatchNorm2d(), Dropout(drop_ratio), Flatten(), Dense(feature_dim), BatchNorm(), name='output_layer') facenet = Sequential(blocks).to(_device) facenet.name = camel2snake('SEResNet_IR') model = FaceRecognitionModel(input_shape=input_shape, output=facenet) model.preprocess_flow = [ Resize((input_shape[1], input_shape[2]), keep_aspect=True), Normalize(0, 255), Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ] #model.summary() return model