Esempio n. 1
0
def test(img_path, anno_path):
    # load net
    num_classes = len(labelmap) + 1  # +1 for background
    net = build_ssd('test', 300, num_classes)  # initialize SSD
    net.load_state_dict(
        torch.load(args.trained_model, map_location=torch.device('cpu')))
    net.eval()
    print('Finished loading model!')
    # load data
    dataset = SIXrayDetection(args.dataset_root,
                              args.dataset,
                              BaseTransform(300, dataset_mean),
                              SIXrayAnnotationTransform(),
                              test_set_path=(img_path, anno_path))
    if args.cuda:
        net = net.cuda()
        cudnn.benchmark = True
    # evaluation
    test_net(args.result_folder,
             net,
             args.cuda,
             dataset,
             BaseTransform(net.size, dataset_mean),
             args.top_k,
             300,
             thresh=args.confidence_threshold)
Esempio n. 2
0
def test(img_path, anno_path):
    # load net
    num_classes = len(SIXray_CLASSES) + 1  # +1 background
    net = build_ssd('test', 300, num_classes)  # initialize SSD
    net.load_state_dict(torch.load(args.trained_model, map_location=torch.device('cpu')))
    net.eval()
    # read and put into a file
    test_sets = []
    for anno_file in os.listdir(anno_path):
        test_sets.append(anno_file.split('.')[0])
    testset = SIXrayDetection(test_sets, None, SIXrayAnnotationTransform(), image_path=img_path, anno_path=anno_path)
    test_net(args.save_folder, net, args.cuda, testset,
             BaseTransform(net.size, (104, 117, 123)),
             thresh=args.visual_threshold)
Esempio n. 3
0
def test_voc():
    # load net
    num_classes = len(SIXray_CLASSES) + 1 # +1 background
    net = build_ssd('test', 300, num_classes) # initialize SSD
    net.load_state_dict(torch.load(args.trained_model,map_location=torch.device('cpu')))
    net.eval()
    print('Finished loading model!')
    # load data
    test_sets = "./data/sixray/test_1650.txt"
    testset = SIXrayDetection(test_sets, None, SIXrayAnnotationTransform())
    if args.cuda:
        net = net.cuda()
        cudnn.benchmark = True
    # evaluation
    test_net(args.save_folder, net, args.cuda, testset,
             BaseTransform(net.size, (104, 117, 123)),
             thresh=args.visual_threshold)
def test_voc():
    # load net
    num_classes = len(SIXray_CLASSES) + 1  # +1 background
    net = build_ssd('test', 300, num_classes)  # initialize SSD
    net.load_state_dict(torch.load(args.trained_model))
    net.eval()
    print('Finished loading model!')
    # load data
    testset = SIXrayDetection(args.sixray_root, [('core_3000', 'val'),
                                                 ('coreless_3000', 'val')],
                              None, SIXrayAnnotationTransform())
    if args.cuda:
        net = net.cuda()
        cudnn.benchmark = True
    # evaluation
    test_net(args.save_folder,
             net,
             args.cuda,
             testset,
             BaseTransform(net.size, (104, 117, 123)),
             thresh=args.visual_threshold)

def evaluate_detections(box_list, output_dir, dataset):
    write_voc_results_file(box_list, dataset)
    do_python_eval(output_dir)


if __name__ == '__main__':
    # load net
    num_classes = len(labelmap) + 1  # +1 for background
    net = build_ssd('test', 300, num_classes)  # initialize SSD
    net.load_state_dict(torch.load(args.trained_model))
    net.eval()
    print('Finished loading model!')
    # load data
    dataset = SIXrayDetection(args.sixray_root, args.imagesetfile,
                              BaseTransform(300, dataset_mean),
                              SIXrayAnnotationTransform())
    if args.cuda:
        net = net.cuda()
        cudnn.benchmark = True
    # evaluation
    test_net(args.save_folder,
             net,
             args.cuda,
             dataset,
             BaseTransform(net.size, dataset_mean),
             args.top_k,
             300,
             thresh=args.confidence_threshold)