def main(_): current_time = datetime.now().strftime("%Y%m%d-%H%M") outdir = os.path.join( FLAGS.outdir, FLAGS.arch + '-' + current_time + '-' + str(os.getpid())) trained_model = os.path.join(outdir, 'trained_model') summary_dir = os.path.join(outdir, 'summary') utils.make_dirs(trained_model) utils.print_arguments(args=FLAGS.__flags, log_fn=os.path.join(outdir, 'args.log')) logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', filename='{}/train.log'.format(outdir), filemode='w', level=logging.INFO) train(trained_model, summary_dir)
# Process arguments args = parser.parse_args() if args.trim <= 0: args.trim = None if args.force_source_file == '': args.force_source_file = None if args.force_source_speaker == '': args.force_source_speaker = None if args.force_target_speaker == '': args.force_target_speaker = None if args.fn_list == '': args.fn_list = 'list_seed' + str( args.seed_input) + '_' + args.split + '.tsv' # Print arguments utils.print_arguments(args) # Seed np.random.seed(args.seed) torch.manual_seed(args.seed) if args.device == 'cuda': torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False torch.cuda.manual_seed(args.seed) ######################################################################################################################## # Load model, pars, & check print('Load stuff') from models import blow
import argparse import functools import paddle from utils.utils import add_arguments, print_arguments, get_lfw_list from utils.utils import get_features, get_feature_dict, test_performance parser = argparse.ArgumentParser(description=__doc__) add_arg = functools.partial(add_arguments, argparser=parser) add_arg('batch_size', int, 64, '训练的批量大小') add_arg('model_path', str, 'models/mobilefacenet/infer/model', 'MobileFaceNet预测模型的路径') add_arg('test_list_path', str, 'dataset/lfw_test.txt', '测试数据的数据列表路径') args = parser.parse_args() print_arguments(args) # 加载模型 model = paddle.jit.load(args.model_path) model.eval() # 获取测试数据 img_paths = get_lfw_list(args.test_list_path) features = get_features(model, img_paths, batch_size=args.batch_size) fe_dict = get_feature_dict(img_paths, features) accuracy, threshold = test_performance(fe_dict, args.test_list_path) print('准确率为:%f, 最优阈值为:%f' % (accuracy, threshold))