├── .gitattributes ├── .gitignore ├── MainModel.py ├── README.md ├── evaluation_protocols └── classifier_metrics │ └── metrics.py ├── images ├── paper_training_algorithm.png └── vggface_tsne_base_ft_models_8.png ├── main.py ├── requirements.txt ├── trainer.py ├── utils.py ├── vggface2_custom_dataset.py └── vggface2_data_manager.py /.gitattributes: -------------------------------------------------------------------------------- 1 | senet50_ft_pytorch.pth filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | *.pyc 3 | *pycache* 4 | *.npy 5 | *.pth 6 | *.ipynb 7 | *.sh 8 | *.idea 9 | *.hdf5 10 | *.sh 11 | *.jpg 12 | *.pdf 13 | *.save 14 | *.png 15 | *.csv 16 | *.prototxt 17 | *.tar 18 | *.pt 19 | *__init__* 20 | *.pyc 21 | *_old* 22 | experiments_results/* -------------------------------------------------------------------------------- /MainModel.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import torch 3 | import torch.nn as nn 4 | import torch.nn.functional as F 5 | 6 | __weights_dict = dict() 7 | 8 | def load_weights(weight_file): 9 | if weight_file == None: 10 | return 11 | 12 | try: 13 | weights_dict = np.load(weight_file).item() 14 | except: 15 | weights_dict = np.load(weight_file, encoding='bytes').item() 16 | 17 | return weights_dict 18 | 19 | class KitModel(nn.Module): 20 | 21 | 22 | def __init__(self, weight_file): 23 | super(KitModel, self).__init__() 24 | global __weights_dict 25 | __weights_dict = load_weights(weight_file) 26 | 27 | self.conv1_7x7_s2 = self.__conv(2, name='conv1/7x7_s2', in_channels=3, out_channels=64, kernel_size=(7, 7), stride=(2, 2), groups=1, bias=False) 28 | self.conv1_7x7_s2_bn = self.__batch_normalization(2, 'conv1/7x7_s2/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 29 | self.conv2_1_1x1_reduce = self.__conv(2, name='conv2_1_1x1_reduce', in_channels=64, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 30 | self.conv2_1_1x1_proj = self.__conv(2, name='conv2_1_1x1_proj', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 31 | self.conv2_1_1x1_reduce_bn = self.__batch_normalization(2, 'conv2_1_1x1_reduce/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 32 | self.conv2_1_1x1_proj_bn = self.__batch_normalization(2, 'conv2_1_1x1_proj/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 33 | self.conv2_1_3x3 = self.__conv(2, name='conv2_1_3x3', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 34 | self.conv2_1_3x3_bn = self.__batch_normalization(2, 'conv2_1_3x3/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 35 | self.conv2_1_1x1_increase = self.__conv(2, name='conv2_1_1x1_increase', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 36 | self.conv2_1_1x1_increase_bn = self.__batch_normalization(2, 'conv2_1_1x1_increase/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 37 | self.conv2_1_1x1_down = self.__conv(2, name='conv2_1_1x1_down', in_channels=256, out_channels=16, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 38 | self.conv2_1_1x1_up = self.__conv(2, name='conv2_1_1x1_up', in_channels=16, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 39 | self.conv2_2_1x1_reduce = self.__conv(2, name='conv2_2_1x1_reduce', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 40 | self.conv2_2_1x1_reduce_bn = self.__batch_normalization(2, 'conv2_2_1x1_reduce/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 41 | self.conv2_2_3x3 = self.__conv(2, name='conv2_2_3x3', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 42 | self.conv2_2_3x3_bn = self.__batch_normalization(2, 'conv2_2_3x3/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 43 | self.conv2_2_1x1_increase = self.__conv(2, name='conv2_2_1x1_increase', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 44 | self.conv2_2_1x1_increase_bn = self.__batch_normalization(2, 'conv2_2_1x1_increase/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 45 | self.conv2_2_1x1_down = self.__conv(2, name='conv2_2_1x1_down', in_channels=256, out_channels=16, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 46 | self.conv2_2_1x1_up = self.__conv(2, name='conv2_2_1x1_up', in_channels=16, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 47 | self.conv2_3_1x1_reduce = self.__conv(2, name='conv2_3_1x1_reduce', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 48 | self.conv2_3_1x1_reduce_bn = self.__batch_normalization(2, 'conv2_3_1x1_reduce/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 49 | self.conv2_3_3x3 = self.__conv(2, name='conv2_3_3x3', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 50 | self.conv2_3_3x3_bn = self.__batch_normalization(2, 'conv2_3_3x3/bn', num_features=64, eps=9.99999974738e-06, momentum=0.0) 51 | self.conv2_3_1x1_increase = self.__conv(2, name='conv2_3_1x1_increase', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 52 | self.conv2_3_1x1_increase_bn = self.__batch_normalization(2, 'conv2_3_1x1_increase/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 53 | self.conv2_3_1x1_down = self.__conv(2, name='conv2_3_1x1_down', in_channels=256, out_channels=16, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 54 | self.conv2_3_1x1_up = self.__conv(2, name='conv2_3_1x1_up', in_channels=16, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 55 | self.conv3_1_1x1_proj = self.__conv(2, name='conv3_1_1x1_proj', in_channels=256, out_channels=512, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=False) 56 | self.conv3_1_1x1_reduce = self.__conv(2, name='conv3_1_1x1_reduce', in_channels=256, out_channels=128, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=False) 57 | self.conv3_1_1x1_proj_bn = self.__batch_normalization(2, 'conv3_1_1x1_proj/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 58 | self.conv3_1_1x1_reduce_bn = self.__batch_normalization(2, 'conv3_1_1x1_reduce/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 59 | self.conv3_1_3x3 = self.__conv(2, name='conv3_1_3x3', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 60 | self.conv3_1_3x3_bn = self.__batch_normalization(2, 'conv3_1_3x3/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 61 | self.conv3_1_1x1_increase = self.__conv(2, name='conv3_1_1x1_increase', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 62 | self.conv3_1_1x1_increase_bn = self.__batch_normalization(2, 'conv3_1_1x1_increase/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 63 | self.conv3_1_1x1_down = self.__conv(2, name='conv3_1_1x1_down', in_channels=512, out_channels=32, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 64 | self.conv3_1_1x1_up = self.__conv(2, name='conv3_1_1x1_up', in_channels=32, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 65 | self.conv3_2_1x1_reduce = self.__conv(2, name='conv3_2_1x1_reduce', in_channels=512, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 66 | self.conv3_2_1x1_reduce_bn = self.__batch_normalization(2, 'conv3_2_1x1_reduce/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 67 | self.conv3_2_3x3 = self.__conv(2, name='conv3_2_3x3', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 68 | self.conv3_2_3x3_bn = self.__batch_normalization(2, 'conv3_2_3x3/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 69 | self.conv3_2_1x1_increase = self.__conv(2, name='conv3_2_1x1_increase', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 70 | self.conv3_2_1x1_increase_bn = self.__batch_normalization(2, 'conv3_2_1x1_increase/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 71 | self.conv3_2_1x1_down = self.__conv(2, name='conv3_2_1x1_down', in_channels=512, out_channels=32, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 72 | self.conv3_2_1x1_up = self.__conv(2, name='conv3_2_1x1_up', in_channels=32, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 73 | self.conv3_3_1x1_reduce = self.__conv(2, name='conv3_3_1x1_reduce', in_channels=512, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 74 | self.conv3_3_1x1_reduce_bn = self.__batch_normalization(2, 'conv3_3_1x1_reduce/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 75 | self.conv3_3_3x3 = self.__conv(2, name='conv3_3_3x3', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 76 | self.conv3_3_3x3_bn = self.__batch_normalization(2, 'conv3_3_3x3/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 77 | self.conv3_3_1x1_increase = self.__conv(2, name='conv3_3_1x1_increase', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 78 | self.conv3_3_1x1_increase_bn = self.__batch_normalization(2, 'conv3_3_1x1_increase/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 79 | self.conv3_3_1x1_down = self.__conv(2, name='conv3_3_1x1_down', in_channels=512, out_channels=32, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 80 | self.conv3_3_1x1_up = self.__conv(2, name='conv3_3_1x1_up', in_channels=32, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 81 | self.conv3_4_1x1_reduce = self.__conv(2, name='conv3_4_1x1_reduce', in_channels=512, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 82 | self.conv3_4_1x1_reduce_bn = self.__batch_normalization(2, 'conv3_4_1x1_reduce/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 83 | self.conv3_4_3x3 = self.__conv(2, name='conv3_4_3x3', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 84 | self.conv3_4_3x3_bn = self.__batch_normalization(2, 'conv3_4_3x3/bn', num_features=128, eps=9.99999974738e-06, momentum=0.0) 85 | self.conv3_4_1x1_increase = self.__conv(2, name='conv3_4_1x1_increase', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 86 | self.conv3_4_1x1_increase_bn = self.__batch_normalization(2, 'conv3_4_1x1_increase/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 87 | self.conv3_4_1x1_down = self.__conv(2, name='conv3_4_1x1_down', in_channels=512, out_channels=32, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 88 | self.conv3_4_1x1_up = self.__conv(2, name='conv3_4_1x1_up', in_channels=32, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 89 | self.conv4_1_1x1_proj = self.__conv(2, name='conv4_1_1x1_proj', in_channels=512, out_channels=1024, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=False) 90 | self.conv4_1_1x1_reduce = self.__conv(2, name='conv4_1_1x1_reduce', in_channels=512, out_channels=256, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=False) 91 | self.conv4_1_1x1_proj_bn = self.__batch_normalization(2, 'conv4_1_1x1_proj/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 92 | self.conv4_1_1x1_reduce_bn = self.__batch_normalization(2, 'conv4_1_1x1_reduce/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 93 | self.conv4_1_3x3 = self.__conv(2, name='conv4_1_3x3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 94 | self.conv4_1_3x3_bn = self.__batch_normalization(2, 'conv4_1_3x3/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 95 | self.conv4_1_1x1_increase = self.__conv(2, name='conv4_1_1x1_increase', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 96 | self.conv4_1_1x1_increase_bn = self.__batch_normalization(2, 'conv4_1_1x1_increase/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 97 | self.conv4_1_1x1_down = self.__conv(2, name='conv4_1_1x1_down', in_channels=1024, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 98 | self.conv4_1_1x1_up = self.__conv(2, name='conv4_1_1x1_up', in_channels=64, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 99 | self.conv4_2_1x1_reduce = self.__conv(2, name='conv4_2_1x1_reduce', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 100 | self.conv4_2_1x1_reduce_bn = self.__batch_normalization(2, 'conv4_2_1x1_reduce/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 101 | self.conv4_2_3x3 = self.__conv(2, name='conv4_2_3x3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 102 | self.conv4_2_3x3_bn = self.__batch_normalization(2, 'conv4_2_3x3/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 103 | self.conv4_2_1x1_increase = self.__conv(2, name='conv4_2_1x1_increase', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 104 | self.conv4_2_1x1_increase_bn = self.__batch_normalization(2, 'conv4_2_1x1_increase/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 105 | self.conv4_2_1x1_down = self.__conv(2, name='conv4_2_1x1_down', in_channels=1024, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 106 | self.conv4_2_1x1_up = self.__conv(2, name='conv4_2_1x1_up', in_channels=64, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 107 | self.conv4_3_1x1_reduce = self.__conv(2, name='conv4_3_1x1_reduce', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 108 | self.conv4_3_1x1_reduce_bn = self.__batch_normalization(2, 'conv4_3_1x1_reduce/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 109 | self.conv4_3_3x3 = self.__conv(2, name='conv4_3_3x3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 110 | self.conv4_3_3x3_bn = self.__batch_normalization(2, 'conv4_3_3x3/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 111 | self.conv4_3_1x1_increase = self.__conv(2, name='conv4_3_1x1_increase', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 112 | self.conv4_3_1x1_increase_bn = self.__batch_normalization(2, 'conv4_3_1x1_increase/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 113 | self.conv4_3_1x1_down = self.__conv(2, name='conv4_3_1x1_down', in_channels=1024, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 114 | self.conv4_3_1x1_up = self.__conv(2, name='conv4_3_1x1_up', in_channels=64, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 115 | self.conv4_4_1x1_reduce = self.__conv(2, name='conv4_4_1x1_reduce', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 116 | self.conv4_4_1x1_reduce_bn = self.__batch_normalization(2, 'conv4_4_1x1_reduce/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 117 | self.conv4_4_3x3 = self.__conv(2, name='conv4_4_3x3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 118 | self.conv4_4_3x3_bn = self.__batch_normalization(2, 'conv4_4_3x3/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 119 | self.conv4_4_1x1_increase = self.__conv(2, name='conv4_4_1x1_increase', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 120 | self.conv4_4_1x1_increase_bn = self.__batch_normalization(2, 'conv4_4_1x1_increase/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 121 | self.conv4_4_1x1_down = self.__conv(2, name='conv4_4_1x1_down', in_channels=1024, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 122 | self.conv4_4_1x1_up = self.__conv(2, name='conv4_4_1x1_up', in_channels=64, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 123 | self.conv4_5_1x1_reduce = self.__conv(2, name='conv4_5_1x1_reduce', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 124 | self.conv4_5_1x1_reduce_bn = self.__batch_normalization(2, 'conv4_5_1x1_reduce/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 125 | self.conv4_5_3x3 = self.__conv(2, name='conv4_5_3x3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 126 | self.conv4_5_3x3_bn = self.__batch_normalization(2, 'conv4_5_3x3/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 127 | self.conv4_5_1x1_increase = self.__conv(2, name='conv4_5_1x1_increase', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 128 | self.conv4_5_1x1_increase_bn = self.__batch_normalization(2, 'conv4_5_1x1_increase/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 129 | self.conv4_5_1x1_down = self.__conv(2, name='conv4_5_1x1_down', in_channels=1024, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 130 | self.conv4_5_1x1_up = self.__conv(2, name='conv4_5_1x1_up', in_channels=64, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 131 | self.conv4_6_1x1_reduce = self.__conv(2, name='conv4_6_1x1_reduce', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 132 | self.conv4_6_1x1_reduce_bn = self.__batch_normalization(2, 'conv4_6_1x1_reduce/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 133 | self.conv4_6_3x3 = self.__conv(2, name='conv4_6_3x3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 134 | self.conv4_6_3x3_bn = self.__batch_normalization(2, 'conv4_6_3x3/bn', num_features=256, eps=9.99999974738e-06, momentum=0.0) 135 | self.conv4_6_1x1_increase = self.__conv(2, name='conv4_6_1x1_increase', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 136 | self.conv4_6_1x1_increase_bn = self.__batch_normalization(2, 'conv4_6_1x1_increase/bn', num_features=1024, eps=9.99999974738e-06, momentum=0.0) 137 | self.conv4_6_1x1_down = self.__conv(2, name='conv4_6_1x1_down', in_channels=1024, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 138 | self.conv4_6_1x1_up = self.__conv(2, name='conv4_6_1x1_up', in_channels=64, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 139 | self.conv5_1_1x1_proj = self.__conv(2, name='conv5_1_1x1_proj', in_channels=1024, out_channels=2048, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=False) 140 | self.conv5_1_1x1_reduce = self.__conv(2, name='conv5_1_1x1_reduce', in_channels=1024, out_channels=512, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=False) 141 | self.conv5_1_1x1_proj_bn = self.__batch_normalization(2, 'conv5_1_1x1_proj/bn', num_features=2048, eps=9.99999974738e-06, momentum=0.0) 142 | self.conv5_1_1x1_reduce_bn = self.__batch_normalization(2, 'conv5_1_1x1_reduce/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 143 | self.conv5_1_3x3 = self.__conv(2, name='conv5_1_3x3', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 144 | self.conv5_1_3x3_bn = self.__batch_normalization(2, 'conv5_1_3x3/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 145 | self.conv5_1_1x1_increase = self.__conv(2, name='conv5_1_1x1_increase', in_channels=512, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 146 | self.conv5_1_1x1_increase_bn = self.__batch_normalization(2, 'conv5_1_1x1_increase/bn', num_features=2048, eps=9.99999974738e-06, momentum=0.0) 147 | self.conv5_1_1x1_down = self.__conv(2, name='conv5_1_1x1_down', in_channels=2048, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 148 | self.conv5_1_1x1_up = self.__conv(2, name='conv5_1_1x1_up', in_channels=128, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 149 | self.conv5_2_1x1_reduce = self.__conv(2, name='conv5_2_1x1_reduce', in_channels=2048, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 150 | self.conv5_2_1x1_reduce_bn = self.__batch_normalization(2, 'conv5_2_1x1_reduce/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 151 | self.conv5_2_3x3 = self.__conv(2, name='conv5_2_3x3', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 152 | self.conv5_2_3x3_bn = self.__batch_normalization(2, 'conv5_2_3x3/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 153 | self.conv5_2_1x1_increase = self.__conv(2, name='conv5_2_1x1_increase', in_channels=512, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 154 | self.conv5_2_1x1_increase_bn = self.__batch_normalization(2, 'conv5_2_1x1_increase/bn', num_features=2048, eps=9.99999974738e-06, momentum=0.0) 155 | self.conv5_2_1x1_down = self.__conv(2, name='conv5_2_1x1_down', in_channels=2048, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 156 | self.conv5_2_1x1_up = self.__conv(2, name='conv5_2_1x1_up', in_channels=128, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 157 | self.conv5_3_1x1_reduce = self.__conv(2, name='conv5_3_1x1_reduce', in_channels=2048, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 158 | self.conv5_3_1x1_reduce_bn = self.__batch_normalization(2, 'conv5_3_1x1_reduce/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 159 | self.conv5_3_3x3 = self.__conv(2, name='conv5_3_3x3', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False) 160 | self.conv5_3_3x3_bn = self.__batch_normalization(2, 'conv5_3_3x3/bn', num_features=512, eps=9.99999974738e-06, momentum=0.0) 161 | self.conv5_3_1x1_increase = self.__conv(2, name='conv5_3_1x1_increase', in_channels=512, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False) 162 | self.conv5_3_1x1_increase_bn = self.__batch_normalization(2, 'conv5_3_1x1_increase/bn', num_features=2048, eps=9.99999974738e-06, momentum=0.0) 163 | self.conv5_3_1x1_down = self.__conv(2, name='conv5_3_1x1_down', in_channels=2048, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 164 | self.conv5_3_1x1_up = self.__conv(2, name='conv5_3_1x1_up', in_channels=128, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True) 165 | self.classifier_1 = self.__dense(name = 'classifier_1', in_features = 2048, out_features = 8631, bias = True) 166 | 167 | def forward(self, x): 168 | conv1_7x7_s2_pad = F.pad(x, (3, 3, 3, 3)) 169 | conv1_7x7_s2 = self.conv1_7x7_s2(conv1_7x7_s2_pad) 170 | conv1_7x7_s2_bn = self.conv1_7x7_s2_bn(conv1_7x7_s2) 171 | conv1_relu_7x7_s2 = F.relu(conv1_7x7_s2_bn) 172 | pool1_3x3_s2_pad = F.pad(conv1_relu_7x7_s2, (0, 1, 0, 1), value=float('-inf')) 173 | pool1_3x3_s2 = F.max_pool2d(pool1_3x3_s2_pad, kernel_size=(3, 3), stride=(2, 2), padding=0, ceil_mode=False) 174 | conv2_1_1x1_reduce = self.conv2_1_1x1_reduce(pool1_3x3_s2) 175 | conv2_1_1x1_proj = self.conv2_1_1x1_proj(pool1_3x3_s2) 176 | conv2_1_1x1_reduce_bn = self.conv2_1_1x1_reduce_bn(conv2_1_1x1_reduce) 177 | conv2_1_1x1_proj_bn = self.conv2_1_1x1_proj_bn(conv2_1_1x1_proj) 178 | conv2_1_1x1_reduce_relu = F.relu(conv2_1_1x1_reduce_bn) 179 | conv2_1_3x3_pad = F.pad(conv2_1_1x1_reduce_relu, (1, 1, 1, 1)) 180 | conv2_1_3x3 = self.conv2_1_3x3(conv2_1_3x3_pad) 181 | conv2_1_3x3_bn = self.conv2_1_3x3_bn(conv2_1_3x3) 182 | conv2_1_3x3_relu = F.relu(conv2_1_3x3_bn) 183 | conv2_1_1x1_increase = self.conv2_1_1x1_increase(conv2_1_3x3_relu) 184 | conv2_1_1x1_increase_bn = self.conv2_1_1x1_increase_bn(conv2_1_1x1_increase) 185 | conv2_1_global_pool = F.avg_pool2d(conv2_1_1x1_increase_bn, kernel_size=(56, 56), stride=(1, 1), padding=(0,), ceil_mode=False) 186 | conv2_1_1x1_down = self.conv2_1_1x1_down(conv2_1_global_pool) 187 | conv2_1_1x1_down_relu = F.relu(conv2_1_1x1_down) 188 | conv2_1_1x1_up = self.conv2_1_1x1_up(conv2_1_1x1_down_relu) 189 | conv2_1_prob = F.sigmoid(conv2_1_1x1_up) 190 | conv2_1_1x1_increase_bn_scale = conv2_1_prob * conv2_1_1x1_increase_bn 191 | conv2_1 = conv2_1_1x1_increase_bn_scale + conv2_1_1x1_proj_bn 192 | conv2_1_relu = F.relu(conv2_1) 193 | conv2_2_1x1_reduce = self.conv2_2_1x1_reduce(conv2_1_relu) 194 | conv2_2_1x1_reduce_bn = self.conv2_2_1x1_reduce_bn(conv2_2_1x1_reduce) 195 | conv2_2_1x1_reduce_relu = F.relu(conv2_2_1x1_reduce_bn) 196 | conv2_2_3x3_pad = F.pad(conv2_2_1x1_reduce_relu, (1, 1, 1, 1)) 197 | conv2_2_3x3 = self.conv2_2_3x3(conv2_2_3x3_pad) 198 | conv2_2_3x3_bn = self.conv2_2_3x3_bn(conv2_2_3x3) 199 | conv2_2_3x3_relu = F.relu(conv2_2_3x3_bn) 200 | conv2_2_1x1_increase = self.conv2_2_1x1_increase(conv2_2_3x3_relu) 201 | conv2_2_1x1_increase_bn = self.conv2_2_1x1_increase_bn(conv2_2_1x1_increase) 202 | conv2_2_global_pool = F.avg_pool2d(conv2_2_1x1_increase_bn, kernel_size=(56, 56), stride=(1, 1), padding=(0,), ceil_mode=False) 203 | conv2_2_1x1_down = self.conv2_2_1x1_down(conv2_2_global_pool) 204 | conv2_2_1x1_down_relu = F.relu(conv2_2_1x1_down) 205 | conv2_2_1x1_up = self.conv2_2_1x1_up(conv2_2_1x1_down_relu) 206 | conv2_2_prob = F.sigmoid(conv2_2_1x1_up) 207 | conv2_2_1x1_increase_bn_scale = conv2_2_prob * conv2_2_1x1_increase_bn 208 | conv2_2 = conv2_2_1x1_increase_bn_scale + conv2_1_relu 209 | conv2_2_relu = F.relu(conv2_2) 210 | conv2_3_1x1_reduce = self.conv2_3_1x1_reduce(conv2_2_relu) 211 | conv2_3_1x1_reduce_bn = self.conv2_3_1x1_reduce_bn(conv2_3_1x1_reduce) 212 | conv2_3_1x1_reduce_relu = F.relu(conv2_3_1x1_reduce_bn) 213 | conv2_3_3x3_pad = F.pad(conv2_3_1x1_reduce_relu, (1, 1, 1, 1)) 214 | conv2_3_3x3 = self.conv2_3_3x3(conv2_3_3x3_pad) 215 | conv2_3_3x3_bn = self.conv2_3_3x3_bn(conv2_3_3x3) 216 | conv2_3_3x3_relu = F.relu(conv2_3_3x3_bn) 217 | conv2_3_1x1_increase = self.conv2_3_1x1_increase(conv2_3_3x3_relu) 218 | conv2_3_1x1_increase_bn = self.conv2_3_1x1_increase_bn(conv2_3_1x1_increase) 219 | conv2_3_global_pool = F.avg_pool2d(conv2_3_1x1_increase_bn, kernel_size=(56, 56), stride=(1, 1), padding=(0,), ceil_mode=False) 220 | conv2_3_1x1_down = self.conv2_3_1x1_down(conv2_3_global_pool) 221 | conv2_3_1x1_down_relu = F.relu(conv2_3_1x1_down) 222 | conv2_3_1x1_up = self.conv2_3_1x1_up(conv2_3_1x1_down_relu) 223 | conv2_3_prob = F.sigmoid(conv2_3_1x1_up) 224 | conv2_3_1x1_increase_bn_scale = conv2_3_prob * conv2_3_1x1_increase_bn 225 | conv2_3 = conv2_3_1x1_increase_bn_scale + conv2_2_relu 226 | conv2_3_relu = F.relu(conv2_3) 227 | conv3_1_1x1_proj = self.conv3_1_1x1_proj(conv2_3_relu) 228 | conv3_1_1x1_reduce = self.conv3_1_1x1_reduce(conv2_3_relu) 229 | conv3_1_1x1_proj_bn = self.conv3_1_1x1_proj_bn(conv3_1_1x1_proj) 230 | conv3_1_1x1_reduce_bn = self.conv3_1_1x1_reduce_bn(conv3_1_1x1_reduce) 231 | conv3_1_1x1_reduce_relu = F.relu(conv3_1_1x1_reduce_bn) 232 | conv3_1_3x3_pad = F.pad(conv3_1_1x1_reduce_relu, (1, 1, 1, 1)) 233 | conv3_1_3x3 = self.conv3_1_3x3(conv3_1_3x3_pad) 234 | conv3_1_3x3_bn = self.conv3_1_3x3_bn(conv3_1_3x3) 235 | conv3_1_3x3_relu = F.relu(conv3_1_3x3_bn) 236 | conv3_1_1x1_increase = self.conv3_1_1x1_increase(conv3_1_3x3_relu) 237 | conv3_1_1x1_increase_bn = self.conv3_1_1x1_increase_bn(conv3_1_1x1_increase) 238 | conv3_1_global_pool = F.avg_pool2d(conv3_1_1x1_increase_bn, kernel_size=(28, 28), stride=(1, 1), padding=(0,), ceil_mode=False) 239 | conv3_1_1x1_down = self.conv3_1_1x1_down(conv3_1_global_pool) 240 | conv3_1_1x1_down_relu = F.relu(conv3_1_1x1_down) 241 | conv3_1_1x1_up = self.conv3_1_1x1_up(conv3_1_1x1_down_relu) 242 | conv3_1_prob = F.sigmoid(conv3_1_1x1_up) 243 | conv3_1_1x1_increase_bn_scale = conv3_1_prob * conv3_1_1x1_increase_bn 244 | conv3_1 = conv3_1_1x1_increase_bn_scale + conv3_1_1x1_proj_bn 245 | conv3_1_relu = F.relu(conv3_1) 246 | conv3_2_1x1_reduce = self.conv3_2_1x1_reduce(conv3_1_relu) 247 | conv3_2_1x1_reduce_bn = self.conv3_2_1x1_reduce_bn(conv3_2_1x1_reduce) 248 | conv3_2_1x1_reduce_relu = F.relu(conv3_2_1x1_reduce_bn) 249 | conv3_2_3x3_pad = F.pad(conv3_2_1x1_reduce_relu, (1, 1, 1, 1)) 250 | conv3_2_3x3 = self.conv3_2_3x3(conv3_2_3x3_pad) 251 | conv3_2_3x3_bn = self.conv3_2_3x3_bn(conv3_2_3x3) 252 | conv3_2_3x3_relu = F.relu(conv3_2_3x3_bn) 253 | conv3_2_1x1_increase = self.conv3_2_1x1_increase(conv3_2_3x3_relu) 254 | conv3_2_1x1_increase_bn = self.conv3_2_1x1_increase_bn(conv3_2_1x1_increase) 255 | conv3_2_global_pool = F.avg_pool2d(conv3_2_1x1_increase_bn, kernel_size=(28, 28), stride=(1, 1), padding=(0,), ceil_mode=False) 256 | conv3_2_1x1_down = self.conv3_2_1x1_down(conv3_2_global_pool) 257 | conv3_2_1x1_down_relu = F.relu(conv3_2_1x1_down) 258 | conv3_2_1x1_up = self.conv3_2_1x1_up(conv3_2_1x1_down_relu) 259 | conv3_2_prob = F.sigmoid(conv3_2_1x1_up) 260 | conv3_2_1x1_increase_bn_scale = conv3_2_prob * conv3_2_1x1_increase_bn 261 | conv3_2 = conv3_2_1x1_increase_bn_scale + conv3_1_relu 262 | conv3_2_relu = F.relu(conv3_2) 263 | conv3_3_1x1_reduce = self.conv3_3_1x1_reduce(conv3_2_relu) 264 | conv3_3_1x1_reduce_bn = self.conv3_3_1x1_reduce_bn(conv3_3_1x1_reduce) 265 | conv3_3_1x1_reduce_relu = F.relu(conv3_3_1x1_reduce_bn) 266 | conv3_3_3x3_pad = F.pad(conv3_3_1x1_reduce_relu, (1, 1, 1, 1)) 267 | conv3_3_3x3 = self.conv3_3_3x3(conv3_3_3x3_pad) 268 | conv3_3_3x3_bn = self.conv3_3_3x3_bn(conv3_3_3x3) 269 | conv3_3_3x3_relu = F.relu(conv3_3_3x3_bn) 270 | conv3_3_1x1_increase = self.conv3_3_1x1_increase(conv3_3_3x3_relu) 271 | conv3_3_1x1_increase_bn = self.conv3_3_1x1_increase_bn(conv3_3_1x1_increase) 272 | conv3_3_global_pool = F.avg_pool2d(conv3_3_1x1_increase_bn, kernel_size=(28, 28), stride=(1, 1), padding=(0,), ceil_mode=False) 273 | conv3_3_1x1_down = self.conv3_3_1x1_down(conv3_3_global_pool) 274 | conv3_3_1x1_down_relu = F.relu(conv3_3_1x1_down) 275 | conv3_3_1x1_up = self.conv3_3_1x1_up(conv3_3_1x1_down_relu) 276 | conv3_3_prob = F.sigmoid(conv3_3_1x1_up) 277 | conv3_3_1x1_increase_bn_scale = conv3_3_prob * conv3_3_1x1_increase_bn 278 | conv3_3 = conv3_3_1x1_increase_bn_scale + conv3_2_relu 279 | conv3_3_relu = F.relu(conv3_3) 280 | conv3_4_1x1_reduce = self.conv3_4_1x1_reduce(conv3_3_relu) 281 | conv3_4_1x1_reduce_bn = self.conv3_4_1x1_reduce_bn(conv3_4_1x1_reduce) 282 | conv3_4_1x1_reduce_relu = F.relu(conv3_4_1x1_reduce_bn) 283 | conv3_4_3x3_pad = F.pad(conv3_4_1x1_reduce_relu, (1, 1, 1, 1)) 284 | conv3_4_3x3 = self.conv3_4_3x3(conv3_4_3x3_pad) 285 | conv3_4_3x3_bn = self.conv3_4_3x3_bn(conv3_4_3x3) 286 | conv3_4_3x3_relu = F.relu(conv3_4_3x3_bn) 287 | conv3_4_1x1_increase = self.conv3_4_1x1_increase(conv3_4_3x3_relu) 288 | conv3_4_1x1_increase_bn = self.conv3_4_1x1_increase_bn(conv3_4_1x1_increase) 289 | conv3_4_global_pool = F.avg_pool2d(conv3_4_1x1_increase_bn, kernel_size=(28, 28), stride=(1, 1), padding=(0,), ceil_mode=False) 290 | conv3_4_1x1_down = self.conv3_4_1x1_down(conv3_4_global_pool) 291 | conv3_4_1x1_down_relu = F.relu(conv3_4_1x1_down) 292 | conv3_4_1x1_up = self.conv3_4_1x1_up(conv3_4_1x1_down_relu) 293 | conv3_4_prob = F.sigmoid(conv3_4_1x1_up) 294 | conv3_4_1x1_increase_bn_scale = conv3_4_prob * conv3_4_1x1_increase_bn 295 | conv3_4 = conv3_4_1x1_increase_bn_scale + conv3_3_relu 296 | conv3_4_relu = F.relu(conv3_4) 297 | conv4_1_1x1_proj = self.conv4_1_1x1_proj(conv3_4_relu) 298 | conv4_1_1x1_reduce = self.conv4_1_1x1_reduce(conv3_4_relu) 299 | conv4_1_1x1_proj_bn = self.conv4_1_1x1_proj_bn(conv4_1_1x1_proj) 300 | conv4_1_1x1_reduce_bn = self.conv4_1_1x1_reduce_bn(conv4_1_1x1_reduce) 301 | conv4_1_1x1_reduce_relu = F.relu(conv4_1_1x1_reduce_bn) 302 | conv4_1_3x3_pad = F.pad(conv4_1_1x1_reduce_relu, (1, 1, 1, 1)) 303 | conv4_1_3x3 = self.conv4_1_3x3(conv4_1_3x3_pad) 304 | conv4_1_3x3_bn = self.conv4_1_3x3_bn(conv4_1_3x3) 305 | conv4_1_3x3_relu = F.relu(conv4_1_3x3_bn) 306 | conv4_1_1x1_increase = self.conv4_1_1x1_increase(conv4_1_3x3_relu) 307 | conv4_1_1x1_increase_bn = self.conv4_1_1x1_increase_bn(conv4_1_1x1_increase) 308 | conv4_1_global_pool = F.avg_pool2d(conv4_1_1x1_increase_bn, kernel_size=(14, 14), stride=(1, 1), padding=(0,), ceil_mode=False) 309 | conv4_1_1x1_down = self.conv4_1_1x1_down(conv4_1_global_pool) 310 | conv4_1_1x1_down_relu = F.relu(conv4_1_1x1_down) 311 | conv4_1_1x1_up = self.conv4_1_1x1_up(conv4_1_1x1_down_relu) 312 | conv4_1_prob = F.sigmoid(conv4_1_1x1_up) 313 | conv4_1_1x1_increase_bn_scale = conv4_1_prob * conv4_1_1x1_increase_bn 314 | conv4_1 = conv4_1_1x1_increase_bn_scale + conv4_1_1x1_proj_bn 315 | conv4_1_relu = F.relu(conv4_1) 316 | conv4_2_1x1_reduce = self.conv4_2_1x1_reduce(conv4_1_relu) 317 | conv4_2_1x1_reduce_bn = self.conv4_2_1x1_reduce_bn(conv4_2_1x1_reduce) 318 | conv4_2_1x1_reduce_relu = F.relu(conv4_2_1x1_reduce_bn) 319 | conv4_2_3x3_pad = F.pad(conv4_2_1x1_reduce_relu, (1, 1, 1, 1)) 320 | conv4_2_3x3 = self.conv4_2_3x3(conv4_2_3x3_pad) 321 | conv4_2_3x3_bn = self.conv4_2_3x3_bn(conv4_2_3x3) 322 | conv4_2_3x3_relu = F.relu(conv4_2_3x3_bn) 323 | conv4_2_1x1_increase = self.conv4_2_1x1_increase(conv4_2_3x3_relu) 324 | conv4_2_1x1_increase_bn = self.conv4_2_1x1_increase_bn(conv4_2_1x1_increase) 325 | conv4_2_global_pool = F.avg_pool2d(conv4_2_1x1_increase_bn, kernel_size=(14, 14), stride=(1, 1), padding=(0,), ceil_mode=False) 326 | conv4_2_1x1_down = self.conv4_2_1x1_down(conv4_2_global_pool) 327 | conv4_2_1x1_down_relu = F.relu(conv4_2_1x1_down) 328 | conv4_2_1x1_up = self.conv4_2_1x1_up(conv4_2_1x1_down_relu) 329 | conv4_2_prob = F.sigmoid(conv4_2_1x1_up) 330 | conv4_2_1x1_increase_bn_scale = conv4_2_prob * conv4_2_1x1_increase_bn 331 | conv4_2 = conv4_2_1x1_increase_bn_scale + conv4_1_relu 332 | conv4_2_relu = F.relu(conv4_2) 333 | conv4_3_1x1_reduce = self.conv4_3_1x1_reduce(conv4_2_relu) 334 | conv4_3_1x1_reduce_bn = self.conv4_3_1x1_reduce_bn(conv4_3_1x1_reduce) 335 | conv4_3_1x1_reduce_relu = F.relu(conv4_3_1x1_reduce_bn) 336 | conv4_3_3x3_pad = F.pad(conv4_3_1x1_reduce_relu, (1, 1, 1, 1)) 337 | conv4_3_3x3 = self.conv4_3_3x3(conv4_3_3x3_pad) 338 | conv4_3_3x3_bn = self.conv4_3_3x3_bn(conv4_3_3x3) 339 | conv4_3_3x3_relu = F.relu(conv4_3_3x3_bn) 340 | conv4_3_1x1_increase = self.conv4_3_1x1_increase(conv4_3_3x3_relu) 341 | conv4_3_1x1_increase_bn = self.conv4_3_1x1_increase_bn(conv4_3_1x1_increase) 342 | conv4_3_global_pool = F.avg_pool2d(conv4_3_1x1_increase_bn, kernel_size=(14, 14), stride=(1, 1), padding=(0,), ceil_mode=False) 343 | conv4_3_1x1_down = self.conv4_3_1x1_down(conv4_3_global_pool) 344 | conv4_3_1x1_down_relu = F.relu(conv4_3_1x1_down) 345 | conv4_3_1x1_up = self.conv4_3_1x1_up(conv4_3_1x1_down_relu) 346 | conv4_3_prob = F.sigmoid(conv4_3_1x1_up) 347 | conv4_3_1x1_increase_bn_scale = conv4_3_prob * conv4_3_1x1_increase_bn 348 | conv4_3 = conv4_3_1x1_increase_bn_scale + conv4_2_relu 349 | conv4_3_relu = F.relu(conv4_3) 350 | conv4_4_1x1_reduce = self.conv4_4_1x1_reduce(conv4_3_relu) 351 | conv4_4_1x1_reduce_bn = self.conv4_4_1x1_reduce_bn(conv4_4_1x1_reduce) 352 | conv4_4_1x1_reduce_relu = F.relu(conv4_4_1x1_reduce_bn) 353 | conv4_4_3x3_pad = F.pad(conv4_4_1x1_reduce_relu, (1, 1, 1, 1)) 354 | conv4_4_3x3 = self.conv4_4_3x3(conv4_4_3x3_pad) 355 | conv4_4_3x3_bn = self.conv4_4_3x3_bn(conv4_4_3x3) 356 | conv4_4_3x3_relu = F.relu(conv4_4_3x3_bn) 357 | conv4_4_1x1_increase = self.conv4_4_1x1_increase(conv4_4_3x3_relu) 358 | conv4_4_1x1_increase_bn = self.conv4_4_1x1_increase_bn(conv4_4_1x1_increase) 359 | conv4_4_global_pool = F.avg_pool2d(conv4_4_1x1_increase_bn, kernel_size=(14, 14), stride=(1, 1), padding=(0,), ceil_mode=False) 360 | conv4_4_1x1_down = self.conv4_4_1x1_down(conv4_4_global_pool) 361 | conv4_4_1x1_down_relu = F.relu(conv4_4_1x1_down) 362 | conv4_4_1x1_up = self.conv4_4_1x1_up(conv4_4_1x1_down_relu) 363 | conv4_4_prob = F.sigmoid(conv4_4_1x1_up) 364 | conv4_4_1x1_increase_bn_scale = conv4_4_prob * conv4_4_1x1_increase_bn 365 | conv4_4 = conv4_4_1x1_increase_bn_scale + conv4_3_relu 366 | conv4_4_relu = F.relu(conv4_4) 367 | conv4_5_1x1_reduce = self.conv4_5_1x1_reduce(conv4_4_relu) 368 | conv4_5_1x1_reduce_bn = self.conv4_5_1x1_reduce_bn(conv4_5_1x1_reduce) 369 | conv4_5_1x1_reduce_relu = F.relu(conv4_5_1x1_reduce_bn) 370 | conv4_5_3x3_pad = F.pad(conv4_5_1x1_reduce_relu, (1, 1, 1, 1)) 371 | conv4_5_3x3 = self.conv4_5_3x3(conv4_5_3x3_pad) 372 | conv4_5_3x3_bn = self.conv4_5_3x3_bn(conv4_5_3x3) 373 | conv4_5_3x3_relu = F.relu(conv4_5_3x3_bn) 374 | conv4_5_1x1_increase = self.conv4_5_1x1_increase(conv4_5_3x3_relu) 375 | conv4_5_1x1_increase_bn = self.conv4_5_1x1_increase_bn(conv4_5_1x1_increase) 376 | conv4_5_global_pool = F.avg_pool2d(conv4_5_1x1_increase_bn, kernel_size=(14, 14), stride=(1, 1), padding=(0,), ceil_mode=False) 377 | conv4_5_1x1_down = self.conv4_5_1x1_down(conv4_5_global_pool) 378 | conv4_5_1x1_down_relu = F.relu(conv4_5_1x1_down) 379 | conv4_5_1x1_up = self.conv4_5_1x1_up(conv4_5_1x1_down_relu) 380 | conv4_5_prob = F.sigmoid(conv4_5_1x1_up) 381 | conv4_5_1x1_increase_bn_scale = conv4_5_prob * conv4_5_1x1_increase_bn 382 | conv4_5 = conv4_5_1x1_increase_bn_scale + conv4_4_relu 383 | conv4_5_relu = F.relu(conv4_5) 384 | conv4_6_1x1_reduce = self.conv4_6_1x1_reduce(conv4_5_relu) 385 | conv4_6_1x1_reduce_bn = self.conv4_6_1x1_reduce_bn(conv4_6_1x1_reduce) 386 | conv4_6_1x1_reduce_relu = F.relu(conv4_6_1x1_reduce_bn) 387 | conv4_6_3x3_pad = F.pad(conv4_6_1x1_reduce_relu, (1, 1, 1, 1)) 388 | conv4_6_3x3 = self.conv4_6_3x3(conv4_6_3x3_pad) 389 | conv4_6_3x3_bn = self.conv4_6_3x3_bn(conv4_6_3x3) 390 | conv4_6_3x3_relu = F.relu(conv4_6_3x3_bn) 391 | conv4_6_1x1_increase = self.conv4_6_1x1_increase(conv4_6_3x3_relu) 392 | conv4_6_1x1_increase_bn = self.conv4_6_1x1_increase_bn(conv4_6_1x1_increase) 393 | conv4_6_global_pool = F.avg_pool2d(conv4_6_1x1_increase_bn, kernel_size=(14, 14), stride=(1, 1), padding=(0,), ceil_mode=False) 394 | conv4_6_1x1_down = self.conv4_6_1x1_down(conv4_6_global_pool) 395 | conv4_6_1x1_down_relu = F.relu(conv4_6_1x1_down) 396 | conv4_6_1x1_up = self.conv4_6_1x1_up(conv4_6_1x1_down_relu) 397 | conv4_6_prob = F.sigmoid(conv4_6_1x1_up) 398 | conv4_6_1x1_increase_bn_scale = conv4_6_prob * conv4_6_1x1_increase_bn 399 | conv4_6 = conv4_6_1x1_increase_bn_scale + conv4_5_relu 400 | conv4_6_relu = F.relu(conv4_6) 401 | conv5_1_1x1_proj = self.conv5_1_1x1_proj(conv4_6_relu) 402 | conv5_1_1x1_reduce = self.conv5_1_1x1_reduce(conv4_6_relu) 403 | conv5_1_1x1_proj_bn = self.conv5_1_1x1_proj_bn(conv5_1_1x1_proj) 404 | conv5_1_1x1_reduce_bn = self.conv5_1_1x1_reduce_bn(conv5_1_1x1_reduce) 405 | conv5_1_1x1_reduce_relu = F.relu(conv5_1_1x1_reduce_bn) 406 | conv5_1_3x3_pad = F.pad(conv5_1_1x1_reduce_relu, (1, 1, 1, 1)) 407 | conv5_1_3x3 = self.conv5_1_3x3(conv5_1_3x3_pad) 408 | conv5_1_3x3_bn = self.conv5_1_3x3_bn(conv5_1_3x3) 409 | conv5_1_3x3_relu = F.relu(conv5_1_3x3_bn) 410 | conv5_1_1x1_increase = self.conv5_1_1x1_increase(conv5_1_3x3_relu) 411 | conv5_1_1x1_increase_bn = self.conv5_1_1x1_increase_bn(conv5_1_1x1_increase) 412 | conv5_1_global_pool = F.avg_pool2d(conv5_1_1x1_increase_bn, kernel_size=(7, 7), stride=(1, 1), padding=(0,), ceil_mode=False) 413 | conv5_1_1x1_down = self.conv5_1_1x1_down(conv5_1_global_pool) 414 | conv5_1_1x1_down_relu = F.relu(conv5_1_1x1_down) 415 | conv5_1_1x1_up = self.conv5_1_1x1_up(conv5_1_1x1_down_relu) 416 | conv5_1_prob = F.sigmoid(conv5_1_1x1_up) 417 | conv5_1_1x1_increase_bn_scale = conv5_1_prob * conv5_1_1x1_increase_bn 418 | conv5_1 = conv5_1_1x1_increase_bn_scale + conv5_1_1x1_proj_bn 419 | conv5_1_relu = F.relu(conv5_1) 420 | conv5_2_1x1_reduce = self.conv5_2_1x1_reduce(conv5_1_relu) 421 | conv5_2_1x1_reduce_bn = self.conv5_2_1x1_reduce_bn(conv5_2_1x1_reduce) 422 | conv5_2_1x1_reduce_relu = F.relu(conv5_2_1x1_reduce_bn) 423 | conv5_2_3x3_pad = F.pad(conv5_2_1x1_reduce_relu, (1, 1, 1, 1)) 424 | conv5_2_3x3 = self.conv5_2_3x3(conv5_2_3x3_pad) 425 | conv5_2_3x3_bn = self.conv5_2_3x3_bn(conv5_2_3x3) 426 | conv5_2_3x3_relu = F.relu(conv5_2_3x3_bn) 427 | conv5_2_1x1_increase = self.conv5_2_1x1_increase(conv5_2_3x3_relu) 428 | conv5_2_1x1_increase_bn = self.conv5_2_1x1_increase_bn(conv5_2_1x1_increase) 429 | conv5_2_global_pool = F.avg_pool2d(conv5_2_1x1_increase_bn, kernel_size=(7, 7), stride=(1, 1), padding=(0,), ceil_mode=False) 430 | conv5_2_1x1_down = self.conv5_2_1x1_down(conv5_2_global_pool) 431 | conv5_2_1x1_down_relu = F.relu(conv5_2_1x1_down) 432 | conv5_2_1x1_up = self.conv5_2_1x1_up(conv5_2_1x1_down_relu) 433 | conv5_2_prob = F.sigmoid(conv5_2_1x1_up) 434 | conv5_2_1x1_increase_bn_scale = conv5_2_prob * conv5_2_1x1_increase_bn 435 | conv5_2 = conv5_2_1x1_increase_bn_scale + conv5_1_relu 436 | conv5_2_relu = F.relu(conv5_2) 437 | conv5_3_1x1_reduce = self.conv5_3_1x1_reduce(conv5_2_relu) 438 | conv5_3_1x1_reduce_bn = self.conv5_3_1x1_reduce_bn(conv5_3_1x1_reduce) 439 | conv5_3_1x1_reduce_relu = F.relu(conv5_3_1x1_reduce_bn) 440 | conv5_3_3x3_pad = F.pad(conv5_3_1x1_reduce_relu, (1, 1, 1, 1)) 441 | conv5_3_3x3 = self.conv5_3_3x3(conv5_3_3x3_pad) 442 | conv5_3_3x3_bn = self.conv5_3_3x3_bn(conv5_3_3x3) 443 | conv5_3_3x3_relu = F.relu(conv5_3_3x3_bn) 444 | conv5_3_1x1_increase = self.conv5_3_1x1_increase(conv5_3_3x3_relu) 445 | conv5_3_1x1_increase_bn = self.conv5_3_1x1_increase_bn(conv5_3_1x1_increase) 446 | conv5_3_global_pool = F.avg_pool2d(conv5_3_1x1_increase_bn, kernel_size=(7, 7), stride=(1, 1), padding=(0,), ceil_mode=False) 447 | conv5_3_1x1_down = self.conv5_3_1x1_down(conv5_3_global_pool) 448 | conv5_3_1x1_down_relu = F.relu(conv5_3_1x1_down) 449 | conv5_3_1x1_up = self.conv5_3_1x1_up(conv5_3_1x1_down_relu) 450 | conv5_3_prob = F.sigmoid(conv5_3_1x1_up) 451 | conv5_3_1x1_increase_bn_scale = conv5_3_prob * conv5_3_1x1_increase_bn 452 | conv5_3 = conv5_3_1x1_increase_bn_scale + conv5_2_relu 453 | conv5_3_relu = F.relu(conv5_3) 454 | pool5_7x7_s1 = F.avg_pool2d(conv5_3_relu, kernel_size=(7, 7), stride=(1, 1), padding=(0,), ceil_mode=False) 455 | classifier_0 = pool5_7x7_s1.view(pool5_7x7_s1.size(0), -1) 456 | classifier_1 = self.classifier_1(classifier_0) 457 | return classifier_0, classifier_1 458 | 459 | 460 | @staticmethod 461 | def __batch_normalization(dim, name, **kwargs): 462 | if dim == 1: layer = nn.BatchNorm1d(**kwargs) 463 | elif dim == 2: layer = nn.BatchNorm2d(**kwargs) 464 | elif dim == 3: layer = nn.BatchNorm3d(**kwargs) 465 | else: raise NotImplementedError() 466 | 467 | if 'scale' in __weights_dict[name]: 468 | layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['scale'])) 469 | else: 470 | layer.weight.data.fill_(1) 471 | 472 | if 'bias' in __weights_dict[name]: 473 | layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias'])) 474 | else: 475 | layer.bias.data.fill_(0) 476 | 477 | layer.state_dict()['running_mean'].copy_(torch.from_numpy(__weights_dict[name]['mean'])) 478 | layer.state_dict()['running_var'].copy_(torch.from_numpy(__weights_dict[name]['var'])) 479 | return layer 480 | 481 | @staticmethod 482 | def __conv(dim, name, **kwargs): 483 | if dim == 1: layer = nn.Conv1d(**kwargs) 484 | elif dim == 2: layer = nn.Conv2d(**kwargs) 485 | elif dim == 3: layer = nn.Conv3d(**kwargs) 486 | else: raise NotImplementedError() 487 | 488 | layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights'])) 489 | if 'bias' in __weights_dict[name]: 490 | layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias'])) 491 | return layer 492 | 493 | @staticmethod 494 | def __dense(name, **kwargs): 495 | layer = nn.Linear(**kwargs) 496 | layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights'])) 497 | if 'bias' in __weights_dict[name]: 498 | layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias'])) 499 | return layer 500 | 501 | @staticmethod 502 | def __dropout(name, **kwargs): 503 | return nn.Dropout(name=name, p=0.5) 504 | 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cross-resolution learning for Face Recognition 2 | 3 | This repository contains the code relative to the paper "[Cross-resolution learning for Face Recognition](https://www.sciencedirect.com/science/article/pii/S0262885620300597)" by Fabio Valerio Massoli (ISTI - CNR), Giuseppe Amato (ISTI - CNR), and Fabrizio Falchi (ISTI - CNR). 4 | 5 | It reports a new training procedure for cross-resolution robust deep neural network. 6 | 7 | **Please note:** 8 | We are researchers, not a software company, and have no personnel devoted to documenting and maintaing this research code. Therefore this code is offered "AS IS". Exact reproduction of the numbers in the paper depends on exact reproduction of many factors, including the version of all software dependencies and the choice of underlying hardware (GPU model, etc). Therefore you should expect to need to re-tune your hyperparameters slightly for your new setup. 9 | 10 | ## Cross-resolution training 11 | 12 | Proposed training approach 13 | 14 |
15 |
16 |
22 |
23 |