-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patheval.py
More file actions
49 lines (41 loc) · 1.32 KB
/
Copy patheval.py
File metadata and controls
49 lines (41 loc) · 1.32 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
#! /usr/bin/env python
# coding=utf-8
# /************************************************************************************
# ***
# *** File Author: Dell, 2018年 09月 21日 星期五 10:25:44 CST
# ***
# ************************************************************************************/
#
import os
import sys
import argparse
import torch
import model
import data
from config import Config
parser = argparse.ArgumentParser(description='Evaluate Text CNN classificer')
parser.add_argument(
'-model',
type=str,
default="model/textcnn.model",
help='filename of pre-trained model [model/textcnn.model]')
if __name__ == '__main__':
conf = Config()
args = parser.parse_args()
print("Loading data...")
test_iter, text_field, label_field = data.fasttext_dataloader(
"data/test.txt", conf.batch_size, shuffle=False)
# model
if os.path.exists(args.model):
print('Loading model from {}...'.format(args.model))
cnn = torch.load(args.model)
else:
print("Model doesn't exist.")
sys.exit(-1)
text_field.vocab = data.load_vocab("model/text.vocab")
label_field.vocab = data.load_vocab("model/label.vocab")
print(cnn)
try:
model.eval(test_iter, cnn, conf)
except Exception as e:
print("Sorry. The test dataset doesn't exist.")