File size: 1,551 Bytes
24be7a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import argparse
import logging
import os.path as osp
import random

import torch

from data.pose_attr_dataset import DeepFashionAttrPoseDataset
from models import create_model
from utils.logger import get_root_logger
from utils.options import dict2str, dict_to_nonedict, parse
from utils.util import make_exp_dirs, set_random_seed


def main():
    # options
    parser = argparse.ArgumentParser()
    parser.add_argument('-opt', type=str, help='Path to option YAML file.')
    args = parser.parse_args()
    opt = parse(args.opt, is_train=False)

    # mkdir and loggers
    make_exp_dirs(opt)
    log_file = osp.join(opt['path']['log'], f"test_{opt['name']}.log")
    logger = get_root_logger(
        logger_name='base', log_level=logging.INFO, log_file=log_file)
    logger.info(dict2str(opt))

    # convert to NoneDict, which returns None for missing keys
    opt = dict_to_nonedict(opt)

    # random seed
    seed = opt['manual_seed']
    if seed is None:
        seed = random.randint(1, 10000)
    logger.info(f'Random seed: {seed}')
    set_random_seed(seed)

    test_dataset = DeepFashionAttrPoseDataset(
        pose_dir=opt['pose_dir'],
        texture_ann_dir=opt['texture_ann_file'],
        shape_ann_path=opt['shape_ann_path'])
    test_loader = torch.utils.data.DataLoader(
        dataset=test_dataset, batch_size=4, shuffle=False)
    logger.info(f'Number of test set: {len(test_dataset)}.')

    model = create_model(opt)
    _ = model.inference(test_loader, opt['path']['results_root'])


if __name__ == '__main__':
    main()