# print(left_up) j += 1 cv2.rectangle(img, left_up, right_bottom, (0, 0, 255), 2) conf = "{:.3f}".format(score) point = (int(left_up[0]), int(left_up[1] - 5)) cv2.putText(img, conf, point, cv2.FONT_HERSHEY_COMPLEX, 0.6, (0, 255, 0), 1) t2 = time.time() print('detect:{} timer:{}'.format(img_path, t2 - t1)) cv2.imwrite(os.path.join(args.save_dir, os.path.basename(img_path)), img) if __name__ == '__main__': net = build_s3fd('test', cfg.NUM_CLASSES) net.load_state_dict(torch.load(args.model)) net.eval() if use_cuda: net.cuda() # cudnn.benckmark = True img_path = './img' # img_path = '/home/lijc08/datasets/widerface/WIDER_val/images/0--Parade' # img_path = './tools/eval_tools/s3fd_val/hard' img_list = [ os.path.join(img_path, x) for x in os.listdir(img_path) if x.endswith('jpg') ] for path in img_list:
from data.config import cfg from s3fd import build_s3fd from utils.augmentations import S3FDBasicTransform parser = argparse.ArgumentParser(description='s3df evaluatuon fddb') parser.add_argument('--trained_model', type=str, default='weights/s3fd.pth', help='trained model') parser.add_argument('--thresh', default=0.1, type=float, help='Final confidence threshold') args = parser.parse_args() use_cuda = torch.cuda.is_available() if use_cuda: torch.set_default_tensor_type('torch.cuda.FloatTensor') else: torch.set_default_tensor_type('torch.FloatTensor') net = build_s3fd('train', cfg.INPUT_SIZE, cfg.NUM_CLASSES) net.load_state_dict(torch.load(args.trained_model)) net.eval() def dyna_anchor(imh, imw): pass
num_workers=args.num_workers, shuffle=True, collate_fn=detection_collate, pin_memory=True) val_batchsize = args.batch_size // 2 val_loader = data.DataLoader(val_dataset, val_batchsize, num_workers=args.num_workers, shuffle=False, collate_fn=detection_collate, pin_memory=True) min_loss = np.inf start_epoch = 0 s3fd_net = build_s3fd('train', cfg.HAND.NUM_CLASSES) net = s3fd_net if args.resume: print('Resuming training, loading {}...'.format(args.resume)) start_epoch = net.load_weights(args.resume) else: vgg_weights = torch.load(args.save_folder + args.basenet) print('Load base network....') net.vgg.load_state_dict(vgg_weights) if args.cuda: if args.multigpu: net = torch.nn.DataParallel(s3fd_net) net = net.cuda()
def eval_wider(model_name): event_list, file_list, imgs_path, save_path = get_data() cfg.USE_NMS = True net = build_s3fd('test', cfg.NUM_CLASSES) net.load_state_dict(torch.load(model_name)) net.eval() if use_cuda: net.cuda() cudnn.benckmark = True # transform = S3FDBasicTransform(cfg.INPUT_SIZE, cfg.MEANS) counter = 0 for index, event in enumerate(tqdm(event_list)): filelist = file_list[index][0] path = os.path.join(save_path, event[0][0].encode('utf-8')) if not os.path.exists(path): os.makedirs(path) for num, file in enumerate(filelist): im_name = file[0][0].encode('utf-8') in_file = os.path.join(imgs_path, event[0][0], im_name[:] + '.jpg') # img = cv2.imread(in_file) img = Image.open(in_file) if img.mode == 'L': img = img.convert('RGB') img = np.array(img) # max_im_shrink = (0x7fffffff / 577.0 / # (img.shape[0] * img.shape[1])) ** 0.5 max_im_shrink = np.sqrt( 1700 * 1200 / (img.shape[0] * img.shape[1])) shrink = max_im_shrink if max_im_shrink < 1 else 1 counter += 1 t1 = time.time() det0 = detect_face(net, img, shrink) det1 = flip_test(net, img, shrink) # flip test [det2, det3] = multi_scale_test(net, img, max_im_shrink) det = np.row_stack((det0, det1, det2, det3)) dets = bbox_vote(det) t2 = time.time() #print('Detect %04d th image costs %.4f' % (counter, t2 - t1)) fout = open(osp.join(save_path, event[0][0].encode('utf-8'), im_name + '.txt'), 'w') fout.write('{:s}\n'.format(event[0][0].encode('utf-8') + '/' + im_name + '.jpg')) fout.write('{:d}\n'.format(dets.shape[0])) for i in xrange(dets.shape[0]): xmin = dets[i][0] ymin = dets[i][1] xmax = dets[i][2] ymax = dets[i][3] score = dets[i][4] fout.write('{:.1f} {:.1f} {:.1f} {:.1f} {:.3f}\n' .format(xmin, ymin, (xmax - xmin + 1), (ymax - ymin + 1), score))