-
Notifications
You must be signed in to change notification settings - Fork 5
/
inference.py
37 lines (28 loc) · 935 Bytes
/
inference.py
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
import os
import torch
import numpy as np
import random
import argparse
import importlib.util
# load the config files
parser = argparse.ArgumentParser(description='Choose the configs to run.')
parser.add_argument('-c', '--config', type=str, required=True)
args = parser.parse_args()
use_config_spec = importlib.util.spec_from_file_location(
args.config, "configs/{}.py".format(args.config))
config_module = importlib.util.module_from_spec(use_config_spec)
use_config_spec.loader.exec_module(config_module)
opt = config_module.opt
# set which gpu to use
os.environ["CUDA_VISIBLE_DEVICES"] = opt.gpu_device
# random seed specification
np.random.seed(opt.seed)
random.seed(opt.seed)
torch.manual_seed(opt.seed)
# init model
from model.model import VDI as Model
model = Model(opt).to(opt.device)
from dataset.feature_dataset import FeatureDataloader
dataloader = FeatureDataloader(opt)
# inference
model.inference(dataloader)