Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support Multi-Scale Training for Text Detection #1714

Open
wants to merge 3 commits into
base: dev-1.x
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions mmocr/models/textdet/module_losses/db_module_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _get_target_single(self, data_sample: TextDetDataSample) -> Tuple:
if self._is_poly_invalid(polygon):
ignore_flags[idx] = True
gt_shrink, ignore_flags = self._generate_kernels(
data_sample.img_shape,
data_sample.batch_input_shape,
gt_instances.polygons,
self.shrink_ratio,
ignore_flags=ignore_flags)
Expand All @@ -249,9 +249,10 @@ def _get_target_single(self, data_sample: TextDetDataSample) -> Tuple:
gt_shrink = gt_shrink > 0

gt_shrink_mask = self._generate_effective_mask(
data_sample.img_shape, gt_instances[ignore_flags].polygons)
data_sample.batch_input_shape, gt_instances[ignore_flags].polygons)
gt_thr, gt_thr_mask = self._generate_thr_map(
data_sample.img_shape, gt_instances[~ignore_flags].polygons)
data_sample.batch_input_shape,
gt_instances[~ignore_flags].polygons)

# to_tensor
gt_shrink = torch.from_numpy(gt_shrink).unsqueeze(0).float()
Expand Down
2 changes: 1 addition & 1 deletion mmocr/models/textdet/module_losses/drrg_module_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def _get_target_single(self, data_sample: TextDetDataSample) -> Tuple:

polygons = gt_instances[~ignore_flags].polygons
ignored_polygons = gt_instances[ignore_flags].polygons
h, w = data_sample.img_shape
h, w = data_sample.batch_input_shape

gt_text_mask = self._generate_text_region_mask((h, w), polygons)
gt_mask = self._generate_effective_mask((h, w), ignored_polygons)
Expand Down
2 changes: 1 addition & 1 deletion mmocr/models/textdet/module_losses/fce_module_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _get_target_single(self, data_sample: TextDetDataSample) -> Tuple:
tuple[Tensor]: A tuple of three tensors from three different
feature level as the targets of one prediction.
"""
img_size = data_sample.img_shape[:2]
img_size = data_sample.batch_input_shape[:2]
text_polys = data_sample.gt_instances.polygons
ignore_flags = data_sample.gt_instances.ignored

Expand Down
4 changes: 2 additions & 2 deletions mmocr/models/textdet/module_losses/pan_module_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ def _get_target_single(self, data_sample: TextDetDataSample
for ratio in self.shrink_ratio:
# TODO pass `gt_ignored` to `_generate_kernels`
gt_kernel, _ = self._generate_kernels(
data_sample.img_shape,
data_sample.batch_input_shape,
gt_polygons,
ratio,
ignore_flags=None,
max_shrink_dist=self.max_shrink_dist)
gt_kernels.append(gt_kernel)
gt_polygons_ignored = data_sample.gt_instances[gt_ignored].polygons
gt_mask = self._generate_effective_mask(data_sample.img_shape,
gt_mask = self._generate_effective_mask(data_sample.batch_input_shape,
gt_polygons_ignored)

gt_kernels = np.stack(gt_kernels, axis=0)
Expand Down
8 changes: 4 additions & 4 deletions mmocr/models/textdet/module_losses/textsnake_module_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ def _get_target_single(self, data_sample: TextDetDataSample) -> Tuple:
polygons = gt_instances[~ignore_flags].polygons
ignored_polygons = gt_instances[ignore_flags].polygons

gt_text_mask = self._generate_text_region_mask(data_sample.img_shape,
polygons)
gt_mask = self._generate_effective_mask(data_sample.img_shape,
gt_text_mask = self._generate_text_region_mask(
data_sample.batch_input_shape, polygons)
gt_mask = self._generate_effective_mask(data_sample.batch_input_shape,
ignored_polygons)

(gt_center_region_mask, gt_radius_map, gt_sin_map,
gt_cos_map) = self._generate_center_mask_attrib_maps(
data_sample.img_shape, polygons)
data_sample.batch_input_shape, polygons)

return (gt_text_mask, gt_mask, gt_center_region_mask, gt_radius_map,
gt_sin_map, gt_cos_map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setUp(self) -> None:
self.db_loss = DBModuleLoss(thr_min=0.3, thr_max=0.7)
self.data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(40, 40)),
metainfo=dict(img_shape=(40, 40), batch_input_shape=(40, 40)),
gt_instances=InstanceData(
polygons=np.array([
[0, 0, 10, 0, 10, 10, 0, 10],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self) -> None:
self.preds = (preds_maps, gcn_pred, gt_labels)
self.data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(64, 64)),
metainfo=dict(img_shape=(64, 64), batch_input_shape=(64, 64)),
gt_instances=InstanceData(
polygons=[
np.array([4, 2, 30, 2, 30, 10, 4, 10]),
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_get_targets(self):
# test generate_targets with blank polygon masks
blank_data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(20, 20)),
metainfo=dict(img_shape=(20, 20), batch_input_shape=(20, 20)),
gt_instances=InstanceData(
polygons=[], ignored=torch.BoolTensor([])))
]
Expand All @@ -77,7 +77,7 @@ def test_get_targets(self):
# test generate_targets with one proposed text component
data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(20, 30)),
metainfo=dict(img_shape=(20, 30), batch_input_shape=(20, 30)),
gt_instances=InstanceData(
polygons=[np.array([13, 6, 17, 6, 17, 14, 13, 14])],
ignored=torch.BoolTensor([False])))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def setUp(self) -> None:
self.fce_loss = FCEModuleLoss(fourier_degree=5, num_sample=400)
self.data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(320, 320)),
metainfo=dict(
img_shape=(320, 320), batch_input_shape=(320, 320)),
gt_instances=InstanceData(
polygons=np.array([
[0, 0, 10, 0, 10, 10, 0, 10],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self) -> None:

self.data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(40, 40)),
metainfo=dict(img_shape=(40, 40), batch_input_shape=(40, 40)),
gt_instances=InstanceData(
polygons=np.array([
[0, 0, 10, 0, 10, 10, 0, 10],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestPSEModuleLoss(TestCase):
def setUp(self) -> None:
self.data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(40, 40)),
metainfo=dict(img_shape=(40, 40), batch_input_shape=(40, 40)),
gt_instances=InstanceData(
polygons=np.array([
[0, 0, 10, 0, 10, 10, 0, 10],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self) -> None:

self.data_samples = [
TextDetDataSample(
metainfo=dict(img_shape=(3, 10)),
metainfo=dict(img_shape=(3, 10), batch_input_shape=(3, 10)),
gt_instances=InstanceData(
polygons=np.array([
[0, 0, 1, 0, 1, 1, 0, 1],
Expand Down