Skip to content

Commit

Permalink
E2E OCR Python Predictor Setup
Browse files Browse the repository at this point in the history
Summary: Python predictor setup for e2e ocr recognition model with detection + recognition. It currently takes non-normalized images (0.0 to 1.0)

Differential Revision: D55776288

fbshipit-source-id: b8779b065f9ad6c1599d50aefbd546c30587eeb1
  • Loading branch information
Alan Li authored and facebook-github-bot committed Apr 23, 2024
1 parent a59f056 commit 181aae3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions detectron2/layers/nms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def batched_nms(

# Note: this function (nms_rotated) might be moved into
# torchvision/ops/boxes.py in the future
@torch.compiler.disable
def nms_rotated(boxes: torch.Tensor, scores: torch.Tensor, iou_threshold: float):
"""
Performs non-maximum suppression (NMS) on the rotated boxes according
Expand Down
1 change: 1 addition & 0 deletions detectron2/layers/roi_align_rotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class _ROIAlignRotated(Function):
@staticmethod
@torch.compiler.disable
def forward(ctx, input, roi, output_size, spatial_scale, sampling_ratio):
ctx.save_for_backward(roi)
ctx.output_size = _pair(output_size)
Expand Down
9 changes: 7 additions & 2 deletions detectron2/modeling/anchor_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def num_anchors(self):
"""
return [len(cell_anchors) for cell_anchors in self.cell_anchors]

def _grid_anchors(self, grid_sizes: List[List[int]]):
def _grid_anchors(self, grid_sizes):
"""
Returns:
list[Tensor]: #featuremap tensors, each is (#locations x #cell_anchors) x 4
Expand Down Expand Up @@ -317,7 +317,12 @@ def num_anchors(self):

def _grid_anchors(self, grid_sizes):
anchors = []
for size, stride, base_anchors in zip(grid_sizes, self.strides, self.cell_anchors):
for size, stride, base_anchors in zip(
grid_sizes,
self.strides,
self.cell_anchors._buffers.values(),
strict=False
):
shift_x, shift_y = _create_grid_offsets(size, stride, self.offset, base_anchors)
zeros = torch.zeros_like(shift_x)
shifts = torch.stack((shift_x, shift_y, zeros, zeros, zeros), dim=1)
Expand Down

0 comments on commit 181aae3

Please sign in to comment.