-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest.py
More file actions
69 lines (55 loc) · 1.58 KB
/
Copy pathtest.py
File metadata and controls
69 lines (55 loc) · 1.58 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
import os
import torch
from net.model import get_model
from net.file_reader import init_dataset, init_transformer
from net.work import test_file
from net.parser import ConfigParser
from net.loader import init
from net.utils import init_thulac
parser = argparse.ArgumentParser()
parser.add_argument('--model', '-m')
parser.add_argument('--gpu', '-g')
parser.add_argument('--config', '-c')
args = parser.parse_args()
configFilePath = args.config
if configFilePath is None:
print("python *.py\t--config/-c\tconfigfile")
usegpu = True
# if args.use is None:
# print("python *.py\t--use/-u\tcpu/gpu")
if args.gpu is None:
usegpu = False
else:
usegpu = True
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu
config = ConfigParser(configFilePath)
config.config.set("train", "train_num_process", 0)
def self_init():
init(config)
init_transformer(config)
init_thulac(config)
self_init()
train_dataset, test_dataset = init_dataset(config)
print("Building net...")
model_name = config.get("net", "name")
net = get_model(model_name, config, usegpu)
print("Net building done.")
print("Loading model...")
net.load_state_dict(torch.load(args.model))
if torch.cuda.is_available() and usegpu:
net = net.cuda()
print("Model loaded.")
print("Testing model...")
test_file(net, test_dataset, usegpu, config, 0)
print("Test done.")
for x in train_dataset.read_process:
x.terminate()
print(x, x.is_alive())
x.join()
print(x, x.is_alive())
for x in test_dataset.read_process:
x.terminate()
print(x, x.is_alive())
x.join()
print(x, x.is_alive())