-
Notifications
You must be signed in to change notification settings - Fork 125
/
eval.py
40 lines (33 loc) · 1.13 KB
/
eval.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
38
39
40
import time
import torch
import subprocess
import os
from model import EAST
from detect import detect_dataset
import numpy as np
import shutil
def eval_model(model_name, test_img_path, submit_path, save_flag=True):
if os.path.exists(submit_path):
shutil.rmtree(submit_path)
os.mkdir(submit_path)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = EAST(False).to(device)
model.load_state_dict(torch.load(model_name))
model.eval()
start_time = time.time()
detect_dataset(model, device, test_img_path, submit_path)
os.chdir(submit_path)
res = subprocess.getoutput('zip -q submit.zip *.txt')
res = subprocess.getoutput('mv submit.zip ../')
os.chdir('../')
res = subprocess.getoutput('python ./evaluate/script.py –g=./evaluate/gt.zip –s=./submit.zip')
print(res)
os.remove('./submit.zip')
print('eval time is {}'.format(time.time()-start_time))
if not save_flag:
shutil.rmtree(submit_path)
if __name__ == '__main__':
model_name = './pths/east_vgg16.pth'
test_img_path = os.path.abspath('../ICDAR_2015/test_img')
submit_path = './submit'
eval_model(model_name, test_img_path, submit_path)