Esempio n. 1
0
 def generate(self):
     model_path = os.path.expanduser(self.model_path)
     assert model_path.endswith('.h5'), 'Keras model or weights must be a .h5 file.'
     
     self.model = facenet(self.input_shape, backbone=self.backbone, mode="predict")
     self.model.load_weights(self.model_path, by_name=True)
     
     self.model.summary()
     print('{} model, anchors, and classes loaded.'.format(model_path))
Esempio n. 2
0
    def generate(self):
        #---------------------------------------------------#
        #   载入模型与权值
        #---------------------------------------------------#
        model_path = os.path.expanduser(self.model_path)
        assert model_path.endswith(
            '.h5'), 'Keras model or weights must be a .h5 file.'
        self.model = facenet(self.input_shape,
                             backbone=self.backbone,
                             mode="predict")

        print('Loading weights into state dict...')
        self.model.load_weights(self.model_path, by_name=True)
        print('{} model loaded.'.format(model_path))
Esempio n. 3
0
    def generate(self):
        # 载入模型
        print('Loading weights into state dict...')
        device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
        model = facenet(backbone=self.backbone, mode="predict")
        model.load_state_dict(torch.load(self.model_path, map_location=device),
                              strict=False)
        self.net = model.eval()

        if self.cuda:
            self.net = torch.nn.DataParallel(self.net)
            cudnn.benchmark = True
            self.net = self.net.cuda()

        print('{} model loaded.'.format(self.model_path))
Esempio n. 4
0
    lfw_dir_path = "lfw"
    lfw_pairs_path = "model_data/lfw_pair.txt"

    #------------------------------------------------------#
    #   设置用到的显卡
    #------------------------------------------------------#
    os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(str(x) for x in train_gpu)
    ngpus_per_node = len(train_gpu)
    print('Number of devices: {}'.format(ngpus_per_node))

    num_classes = get_num_classes(annotation_path)
    #---------------------------------#
    #   载入模型并加载预训练权重
    #---------------------------------#
    model_body = facenet(input_shape,
                         num_classes,
                         backbone=backbone,
                         mode="train")
    if model_path != '':
        #------------------------------------------------------#
        #   载入预训练权重
        #------------------------------------------------------#
        print('Load weights {}.'.format(model_path))
        model_body.load_weights(model_path, by_name=True, skip_mismatch=True)

    if ngpus_per_node > 1:
        model = multi_gpu_model(model_body, gpus=ngpus_per_node)
    else:
        model = model_body
    #-------------------------------------------------------#
    #   0.01用于验证,0.99用于训练
    #-------------------------------------------------------#
Esempio n. 5
0
    #--------------------------------------#
    input_shape = [160, 160, 3]
    #--------------------------------------#
    #   训练好的权值文件
    #--------------------------------------#
    model_path = "model_data/facenet_mobilenet.h5"
    #--------------------------------------#
    #   LFW评估数据集的文件路径
    #   以及对应的txt文件
    #--------------------------------------#
    lfw_dir_path = "lfw"
    lfw_pairs_path = "model_data/lfw_pair.txt"
    #--------------------------------------#
    #   评估的批次大小和记录间隔
    #--------------------------------------#
    batch_size = 256
    log_interval = 1
    #--------------------------------------#
    #   ROC图的保存路径
    #--------------------------------------#
    png_save_path = "model_data/roc_test.png"

    test_loader = LFWDataset(dir=lfw_dir_path,
                             pairs_path=lfw_pairs_path,
                             batch_size=batch_size,
                             input_shape=input_shape)

    model = facenet(input_shape, backbone=backbone, mode="predict")
    model.load_weights(model_path, by_name=True)

    test(test_loader, model, png_save_path, log_interval, batch_size)
Esempio n. 6
0
#--------------------------------------------#
#   该部分代码只用于看网络结构,并非测试代码
#--------------------------------------------#
import os

from nets.facenet import facenet

if __name__ == "__main__":
    input_shape = [160, 160, 3]
    model = facenet(input_shape,
                    len(os.listdir("./datasets")),
                    backbone="inception_resnetv1",
                    mode="train")
    model.summary()

    for i, layer in enumerate(model.layers):
        print(i, layer.name)
Esempio n. 7
0
#--------------------------------------------#
#   该部分代码只用于看网络结构,并非测试代码
#--------------------------------------------#
from nets.facenet import facenet
from utils.utils import net_flops

if __name__ == "__main__":
    input_shape = [160, 160]
    backbone = "mobilenet"
    model = facenet([input_shape[0], input_shape[1], 3],
                    10575,
                    backbone=backbone,
                    mode="train")
    #--------------------------------------------#
    #   查看网络结构网络结构
    #--------------------------------------------#
    model.summary()
    #------------------------------------------#
    #   计算网络的FLOPS
    #--------------------------------------------#
    net_flops(model, table=False)

    #--------------------------------------------#
    #   获得网络每个层的名称与序号
    #--------------------------------------------#
    # for i,layer in enumerate(model.layers):
    #     print(i,layer.name)