Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions doctr/models/detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ def box_score(pred: np.ndarray, points: np.ndarray, assume_straight_pages: bool
return pred[ymin : ymax + 1, xmin : xmax + 1].mean()

else:
mask: np.ndarray = np.zeros((h, w), np.int32)
cv2.fillPoly(mask, [points.astype(np.int32)], 1.0)
product = pred * mask
return np.sum(product) / np.count_nonzero(product)
pts: np.ndarray = points.reshape((-1, 2)).astype(np.int32)
xmin = np.clip(pts[:, 0].min(), 0, w - 1)
xmax = np.clip(pts[:, 0].max(), 0, w - 1)
ymin = np.clip(pts[:, 1].min(), 0, h - 1)
ymax = np.clip(pts[:, 1].max(), 0, h - 1)
mask: np.ndarray = np.zeros((ymax - ymin + 1, xmax - xmin + 1), dtype=np.uint8)
cv2.fillPoly(mask, [pts - np.array([[xmin, ymin]], dtype=np.int32)], 1)
vals = pred[ymin : ymax + 1, xmin : xmax + 1][mask.astype(bool)]
nonzero = np.count_nonzero(vals)
return float(vals.sum() / nonzero) if nonzero > 0 else 0.0

def bitmap_to_boxes(
self,
Expand Down
1 change: 0 additions & 1 deletion doctr/models/preprocessor/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def __call__(
samples = list(multithread_exec(self.sample_transforms, x))
# Batching
if self.resize.return_padding_mask:
print(samples)
img_batches, mask_batches = self.batch_inputs(samples)
else:
img_batches = self.batch_inputs(samples)
Expand Down
Loading