Skip to content
Snippets Groups Projects
Verified Commit 88f53144 authored by Mélodie Boillet's avatar Mélodie Boillet
Browse files

Remove padding for ctc loss

parent e01751a4
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,6 @@ from dan.ocr.utils import LM_str_to_ind
from dan.utils import (
pad_image,
pad_image_width_random,
pad_image_width_right,
pad_images,
pad_sequences_1D,
rand,
......@@ -154,37 +153,7 @@ class OCRDataset(GenericDataset):
sample["img_shape"] / self.reduce_dims_factor
).astype(int)
# Padding to handle CTC requirements
if self.set_name == "train":
max_label_len = 0
height = 1
ctc_padding = False
if "CTC_line" in self.params["config"]["constraints"]:
max_label_len = sample["label_len"]
ctc_padding = True
if "CTC_va" in self.params["config"]["constraints"]:
max_label_len = max(sample["line_label_len"])
ctc_padding = True
if "CTC_pg" in self.params["config"]["constraints"]:
max_label_len = sample["label_len"]
height = max(sample["img_reduced_shape"][0], 1)
ctc_padding = True
if (
ctc_padding
and 2 * max_label_len + 1 > sample["img_reduced_shape"][1] * height
):
sample["img"] = pad_image_width_right(
sample["img"],
int(
np.ceil((2 * max_label_len + 1) / height)
* self.reduce_dims_factor[1]
),
self.padding_value,
)
sample["img_shape"] = sample["img"].shape
sample["img_reduced_shape"] = np.ceil(
sample["img_shape"] / self.reduce_dims_factor
).astype(int)
sample["img_reduced_shape"] = [
max(1, t) for t in sample["img_reduced_shape"]
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment