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

fix lateocr bug #13920

Merged
merged 1 commit into from
Sep 28, 2024
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
4 changes: 4 additions & 0 deletions ppocr/modeling/backbones/rec_resnetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def __init__(
self.eps = eps

def forward(self, x):
if not self.training:
self.export = True
if self.same_pad:
if self.export:
x = pad_same_export(x, self._kernel_size, self._stride, self._dilation)
Expand Down Expand Up @@ -201,6 +203,8 @@ def __init__(
)

def forward(self, x):
if not self.training:
self.export = True
if self.export:
x = pad_same_export(x, self.ksize, self.stride, value=-float("inf"))
else:
Expand Down
3 changes: 3 additions & 0 deletions ppocr/modeling/heads/rec_latexocr_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def forward(
mem=None,
seq_len=0,
):
if not self.training:
self.is_export = True
b, n, _, h, talking_heads, collab_heads, has_context = (
*x.shape,
self.heads,
Expand Down Expand Up @@ -987,6 +989,7 @@ def generate_export(
# forward for export
def forward(self, inputs, targets=None):
if not self.training:
self.is_export = True
encoded_feat = inputs
batch_num = encoded_feat.shape[0]
bos_tensor = paddle.full([batch_num, 1], self.bos_token, dtype=paddle.int64)
Expand Down
1 change: 1 addition & 0 deletions ppocr/utils/export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def dump_infer_config(config, path, logger):
if hpi_config["Hpi"]["backend_config"].get("tensorrt", None):
hpi_config["Hpi"]["supported_backends"]["gpu"].remove("tensorrt")
del hpi_config["Hpi"]["backend_config"]["tensorrt"]
hpi_config["Hpi"]["selected_backends"]["gpu"] = "paddle_infer"
infer_cfg["Hpi"] = hpi_config["Hpi"]
if config["Global"].get("pdx_model_name", None):
infer_cfg["Global"] = {}
Expand Down
6 changes: 5 additions & 1 deletion ppocr/utils/save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def update_train_results(config, prefix, metric_info, done_flag=False, last_num=
metric_score = metric_info["metric"]["acc"]
elif "precision" in metric_info["metric"]:
metric_score = metric_info["metric"]["precision"]
elif "exp_rate" in metric_info["metric"]:
metric_score = metric_info["metric"]["exp_rate"]
else:
raise ValueError("No metric score found.")
train_results["models"]["best"]["score"] = metric_score
Expand All @@ -326,8 +328,10 @@ def update_train_results(config, prefix, metric_info, done_flag=False, last_num=
metric_score = metric_info["metric"]["acc"]
elif "precision" in metric_info["metric"]:
metric_score = metric_info["metric"]["precision"]
elif "exp_rate" in metric_info["metric"]:
metric_score = metric_info["metric"]["exp_rate"]
else:
raise ValueError("No metric score found.")
metric_score = 0
train_results["models"][f"last_{1}"]["score"] = metric_score
for tag in save_model_tag:
train_results["models"][f"last_{1}"][tag] = os.path.join(
Expand Down