示例#1
0
def test_model(model, test_images, num_init):
    face_detector = menpodetect.load_dlib_frontal_face_detector()
    test_gt_shapes = util.get_gt_shapes(test_images)
    test_boxes = util.get_bounding_boxes(test_images, test_gt_shapes, face_detector)

    initial_errors = []
    final_errors = []

    initial_shapes = []
    final_shapes = []

    for k, (im, gt_shape, box) in enumerate(zip(test_images, test_gt_shapes, test_boxes)):
        init_shapes, fin_shapes = model.apply(im, ([box], num_init, None))

        init_shape = util.get_median_shape(init_shapes)
        final_shape = fin_shapes[0]

        initial_shapes.append(init_shape)
        final_shapes.append(final_shape)

        initial_errors.append(compute_error(init_shape, gt_shape))
        final_errors.append(compute_error(final_shape, gt_shape))

        print_dynamic('{}/{}'.format(k + 1, len(test_images)))

    return initial_errors, final_errors, initial_shapes, final_shapes
示例#2
0
    def apply(self, image, extra):
        boxes, init_num, initial_shapes = extra

        if initial_shapes is None:
            initial_shapes = np.array([fit_shape_to_box(self.mean_shape, box) for box in boxes])

        shapes = deepcopy(initial_shapes)

        for i, shape in enumerate(shapes):
            init_shapes = util.perturb_init_shape(initial_shapes[i].copy(), init_num)
            for j in xrange(init_num):
                for r in self.weak_regressors:
                    offset = r.apply(image, init_shapes[j])
                    init_shapes[j].points += offset.points
            shape.points[:] = util.get_median_shape(init_shapes).points

        return initial_shapes, shapes
示例#3
0
    def apply(self, image, extra):
        boxes, init_num, initial_shapes = extra

        if initial_shapes is None:
            initial_shapes = np.array(
                [fit_shape_to_box(self.mean_shape, box) for box in boxes])

        shapes = deepcopy(initial_shapes)

        for i, shape in enumerate(shapes):
            init_shapes = util.perturb_init_shape(initial_shapes[i].copy(),
                                                  init_num)
            for j in xrange(init_num):
                for r in self.weak_regressors:
                    offset = r.apply(image, init_shapes[j])
                    init_shapes[j].points += offset.points
            shape.points[:] = util.get_median_shape(init_shapes).points

        return initial_shapes, shapes