Ejemplo n.º 1
0
def get_hidden_detections(sess,
                          H,
                          hidden_x_in,
                          hidden_pred_boxes,
                          hidden_pred_confidences,
                          page_images: List[np.ndarray],
                          crop_whitespace: bool = True,
                          conf_threshold: float = .5) -> List[List[BoxClass]]:
    input_shape = [H['image_height'], H['image_width'], H['image_channels']]
    page_datas = [{
        'page_image':
        page_image,
        'orig_size':
        page_image.shape[:2],
        'resized_page_image':
        image_util.imresize_multichannel(page_image, input_shape),
    } for page_image in page_images]

    predictions = [
        sess.run([hidden_pred_boxes, hidden_pred_confidences],
                 feed_dict={hidden_x_in: page_data['resized_page_image']})
        for page_data in page_datas
    ]

    for (page_data, prediction) in zip(page_datas, predictions):
        (np_pred_boxes, np_pred_confidences) = prediction
        new_img, rects = train_utils.add_rectangles(
            H,
            page_data['resized_page_image'],
            np_pred_confidences,
            np_pred_boxes,
            use_stitching=True,
            min_conf=conf_threshold,
            show_suppressed=False)
        detected_boxes = [
            BoxClass(x1=r.x1, y1=r.y1, x2=r.x2,
                     y2=r.y2).resize_by_page(input_shape,
                                             page_data['orig_size'])
            for r in rects if r.score > conf_threshold
        ]
        if crop_whitespace:
            detected_boxes = [
                box.crop_whitespace_edges(page_data['page_image'])
                for box in detected_boxes
            ]
            detected_boxes = list(filter(None, detected_boxes))
        page_data['detected_boxes'] = detected_boxes
    return [page_data['detected_boxes'] for page_data in page_datas]
Ejemplo n.º 2
0
def evaluate_dataset_on_weights(hidden_set_dir: str, hidden_set_images_subdir: str, save_dir: str, iteration: int):
    detector_args = {
        'save_dir': save_dir,
        'iteration': iteration
    }
    detector = get_detector(detector_args=detector_args)
    annos = json.load(open(os.path.join(hidden_set_dir, 'figure_boundaries.json')))

    for anno in annos:
        image_np = imageio.imread(os.path.join(hidden_set_dir, hidden_set_images_subdir, anno['image_path']))
        pred_boxes = detector.get_detections([image_np])[0]
        true_boxes = [BoxClass(x1=rect['x1'], y1=rect['y1'], x2=rect['x2'], y2=rect['y2']) for rect in anno['rects']]
        (pred_indices, true_indices) = figure_utils.pair_boxes(pred_boxes, true_boxes)
        print("Pred boxes: ", pred_boxes)
        print("True boxes: ", true_boxes)
        print("Pred indices: ", pred_indices)
        print("True indices: ", true_indices)
        a = 0
Ejemplo n.º 3
0
def rect_to_box_class(rect: Dict) -> BoxClass:
    return BoxClass(x1=rect['x1'], y1=rect['y1'], x2=rect['x2'], y2=rect['y2'])