Ejemplo n.º 1
0
def test_net(root_path,
             dataset_path,
             image_set,
             prefix,
             epoch,
             batch_size,
             ctx,
             test_mode="hardpnet20",
             thresh=[0.6, 0.6, 0.7],
             min_face_size=24):

    thread_num = len(ctx)
    mtcnn_detectors = list()
    for i in range(thread_num):
        mtcnn_detectors.append(
            creat_mtcnn_detector(prefix, epoch, batch_size, test_mode, thresh,
                                 min_face_size, ctx[i]))

    imdb = IMDB("wider", image_set, root_path, dataset_path, 'test')
    annotations = imdb.get_annotations()

    image_num = len(annotations)
    test_batch_size = 10 * thread_num
    start_idx = 0
    detections = list()
    while start_idx < image_num:
        end_idx = min(start_idx + test_batch_size, image_num)
        cur_annotations = annotations[start_idx:end_idx]
        cur_detections = test_minibatch(cur_annotations, mtcnn_detectors)
        detections = detections + cur_detections
        start_idx = end_idx
        print '%d images done' % start_idx

    return detections
Ejemplo n.º 2
0
def train_O_net(image_set, root_path, dataset_path, prefix, ctx,
                pretrained, epoch, begin_epoch, end_epoch, batch_size, thread_num, 
                frequent, lr,lr_epoch, resume, with_landmark):
    imdb = IMDB("mtcnn", image_set, root_path, dataset_path, 'train')
    gt_imdb = imdb.get_annotations()
    sym = O_Net('train',with_landmark)

    train_net(sym, prefix, ctx, pretrained, epoch, begin_epoch, end_epoch, gt_imdb, batch_size, thread_num,
              48, True, True, with_landmark, frequent, not resume, lr, lr_epoch)
Ejemplo n.º 3
0
def train_R_net(image_set, root_path, dataset_path, prefix, ctx,
                pretrained, epoch, begin_epoch, end_epoch, batch_size, thread_num,
                frequent, lr, lr_epoch, resume):
    imdb = IMDB("mtcnn", image_set, root_path, dataset_path, 'train')
    gt_imdb = imdb.get_annotations()
    sym = R_Net()

    train_net(sym, prefix, ctx, pretrained, epoch, begin_epoch, end_epoch, gt_imdb, batch_size, thread_num,
              24, True, True, False, frequent, not resume, lr, lr_epoch)
Ejemplo n.º 4
0
def test_net(root_path,
             dataset_path,
             prefix,
             epoch,
             batch_size,
             ctx,
             test_mode="onet",
             thresh=[0.6, 0.6, 0.7],
             min_face_size=24):

    detectors = [None, None, None]

    # load pnet model
    args, auxs = load_param(prefix[0], epoch[0], convert=True, ctx=ctx)
    PNet = FcnDetector(P_Net20("test"), ctx, args, auxs)
    detectors[0] = PNet

    # load rnet model
    if test_mode in ["rnet", "onet"]:
        args, auxs = load_param(prefix[1], epoch[1], convert=True, ctx=ctx)
        RNet = Detector(R_Net("test"), 24, batch_size[1], ctx, args, auxs)
        detectors[1] = RNet

    # load onet model
    if test_mode == "onet":
        args, auxs = load_param(prefix[2], epoch[2], convert=True, ctx=ctx)
        ONet = Detector(O_Net("test", False), 48, batch_size[2], ctx, args,
                        auxs)
        detectors[2] = ONet

    mtcnn_detector = MtcnnDetector(detectors=detectors,
                                   ctx=ctx,
                                   min_face_size=min_face_size,
                                   stride=4,
                                   threshold=thresh,
                                   slide_window=False)

    for i in range(1, 11):
        image_set = "fold-" + str(i).zfill(2)
        imdb = IMDB("fddb", image_set, root_path, dataset_path, 'test')
        gt_imdb = imdb.get_annotations()

        test_data = TestLoader(gt_imdb)
        all_boxes = mtcnn_detector.detect_face(imdb, test_data, vis=False)
        imdb.write_results(all_boxes)