forked from ShuangXieIrene/ssds.pytorch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
63 lines (52 loc) · 1.97 KB
/
test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from __future__ import print_function
import sys
import os
import argparse
import numpy as np
if '/data/software/opencv-3.4.0/lib/python2.7/dist-packages' in sys.path:
sys.path.remove('/data/software/opencv-3.4.0/lib/python2.7/dist-packages')
if '/data/software/opencv-3.3.1/lib/python2.7/dist-packages' in sys.path:
sys.path.remove('/data/software/opencv-3.3.1/lib/python2.7/dist-packages')
import cv2
from datetime import datetime
import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
from torch.autograd import Variable
from lib.utils.config_parse import cfg_from_file
from lib.ssds_train import test_model, test_image, export_onnx_model
def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Train a ssds.pytorch network')
parser.add_argument('--cfg', dest='config_file',
help='optional config file', default=None, type=str)
parser.add_argument('--onnx', dest='onnx_file',
help='optional onnx_file to be exported', default=None, type=str)
parser.add_argument('--single_image', dest='single_image',
help='inference objects from image', default=None, type=str)
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
return args
def test():
test_model()
def test_single_image(image_path):
image = cv2.imread(image_path)
test_image(image)
cv2.imwrite('/tmp/np_result.jpg', image)
if __name__ == '__main__':
args = parse_args()
if args.config_file is not None:
cfg_from_file(args.config_file)
if args.onnx_file is not None:
export_onnx_model(args.onnx_file)
elif args.single_image is not None:
test_single_image(args.single_image)
#export_onnx_model("/tmp/bayer_ssd_lite_mbv2.onnx")
#test_single_image('/mnt/500GB/datasets/Bayer_0315/photos/1.jpg')
#test_single_image('/tmp/900x600.jpg')
else:
test_model()