Ejemplo n.º 1
0
            if bbox_in_expand_region(gt_bbox, all_expand_boxes[idx]):
                nrecall += 1

    print("expand region recall")
    print("{}/{}: {:.4f}".format(nrecall, npos, nrecall/npos))


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
    net = build_ssd('test', args.input_size, args.input_size_2, 2, args.expand_num)            # initialize SSD
    net.load_state_dict(torch.load(args.trained_model))
    net.eval()
    print('Finished loading model!')
    # load data
    dataset = CAR_CARPLATEDetection(root=args.voc_root,
                           transform=BaseTransform(args.input_size, dataset_mean),
                           target_transform=CAR_CARPLATEAnnotationTransform(keep_difficult=True),
                           dataset_name=set_type)
    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, args.input_size,
             thresh=args.confidence_threshold)
Ejemplo n.º 2
0
                    default='weights/voc_weights/VOC300.pth', type=str,
                    help='Trained state_dict file path to open')
parser.add_argument('--obj_type', default='car_carplate', choices=['car_carplate', 'car', 'carplate'],
                    type=str, help='car or carplate')
args = parser.parse_args()

if args.obj_type in ['car', 'carplate']:
    net = build_ssd('test', args.input_size, 2)    # initialize SSD
elif args.obj_type == 'car_carplate':
    net = build_ssd('test', args.input_size, 3)
net.load_weights(args.trained_model)

# matplotlib inline
from matplotlib import pyplot as plt
from data import CAR_CARPLATEDetection, CAR_CARPLATEAnnotationTransform, CAR_CARPLATE_ROOT
testset = CAR_CARPLATEDetection(CAR_CARPLATE_ROOT, None, None, CAR_CARPLATEAnnotationTransform(),
                                       dataset_name='test')
for img_id in range(100):
    image = testset.pull_image(img_id)
    rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    x = cv2.resize(image, (args.input_size, args.input_size)).astype(np.float32)
    x -= (104.0, 117.0, 123.0)
    x = x.astype(np.float32)
    x = x[:, :, ::-1].copy()
    x = torch.from_numpy(x).permute(2, 0, 1)

    xx = Variable(x.unsqueeze(0))     # wrap tensor in Variable
    if torch.cuda.is_available():
        xx = xx.cuda()

    y = net(xx)