def main(args): torch.set_grad_enabled(False) device = torch.device(args.device) # Initialize the net and load the model print('Loading pretrained model from {}'.format(args.trained_model)) net = YuFaceDetectNet(phase='test', size=None) net = load_model(net, args.trained_model) net.eval() if device.type == 'cuda': cudnn.benchmark = True net = net.to(device) print('Finished loading model!') # init data loader for WIDER Face print('Loading data for {}...'.format(args.widerface_split)) widerface = WIDERFace(args.widerface_root, split=args.widerface_split) print('Finished loading data!') # start testing scales = [] if args.multi_scale: scales = [0.25, 0.50, 0.75, 1.25, 1.50, 1.75, 2.0] print('Performing testing with scales: 1. {}, conf_threshold: {}'.format( str(scales), args.confidence_threshold)) priors_dict = {} for idx in tqdm(range(len(widerface))): img, event, name = widerface[idx] # img_subpath = '0--Parade/XXX.jpg' if img.shape in priors_dict: priors = priors_dict[img.shape] else: height, width, _ = img.shape priors = PriorBox(cfg, image_size=(height, width)).forward() priors_dict[img.shape] = priors dets = detect_face(net, img, priors, device) available_scales = get_available_scales(img.shape[0], img.shape[1], scales) for available_scale in available_scales: det = detect_face(net, img, None, device, scale=available_scale) if det.shape[0] != 0: dets = np.row_stack((dets, det)) # nms dets = nms_opencv(dets, score_thresh=args.confidence_threshold, nms_thresh=args.nms_threshold, top_k=args.top_k, keep_top_k=args.keep_top_k) save_res(dets, event, name) # widerface_eval print('Evaluating:') evaluation(args.res_dir, os.path.join(args.widerface_root, 'eval_tools/ground_truth'))
def main(args): torch.set_grad_enabled(False) device = torch.device(args.device) # Initialize the net and load the model print('Loading pretrained model from {}'.format(args.trained_model)) net = YuFaceDetectNet(phase='test', size=None) net = load_model(net, args.trained_model) net.eval() if device.type == 'cuda': cudnn.benchmark = True net = net.to(device) print('Finished loading model!') # init data loader for WIDER Face print('Loading data for {}...'.format(args.widerface_split)) widerface = WIDERFace(args.widerface_root, split=args.widerface_split) print('Finished loading data!') # start testing scales = [1.] if args.multi_scale: scales = [0.25, 0.50, 0.75, 1.25, 1.50, 1.75, 2.0] print('Performing testing with scales: {}, conf_threshold: {}'.format( str(scales), args.confidence_threshold)) for idx in tqdm(range(len(widerface))): img, event, name = widerface[idx] # img_subpath = '0--Parade/XXX.jpg' dets = detect_face(net, img, device, conf_thresh=args.confidence_threshold) available_scales = get_available_scales(img.shape[0], img.shape[1], scales) for available_scale in available_scales: det = detect_face(net, img, device, scale=available_scale, conf_thresh=args.confidence_threshold) if det is not None: dets = np.row_stack((dets, det)) # nms dets = simple_nms(dets) # dets = bbox_vote(dets) save_res(dets, event, name)
net = load_model(net, args.trained_model, True) #net.load_state_dict(torch.load(args.trained_model)) net.eval() print('Finished loading model!') ## Print model's state_dict #print("Model's state_dict:") #for param_tensor in net.state_dict(): # print(param_tensor, "\t", net.state_dict()[param_tensor].size()) #print(net) cudnn.benchmark = True net = net.to(device) _t = {'forward_pass': Timer(), 'misc': Timer()} # testing begin img_raw = cv2.imread(args.image_file, cv2.IMREAD_COLOR) img = np.float32(img_raw) im_height, im_width, _ = img.shape #img -= (104, 117, 123) img = img.transpose(2, 0, 1) img = torch.from_numpy(img).unsqueeze(0) img = img.to(device) scale = torch.Tensor([ im_width, im_height, im_width, im_height, im_width, im_height,