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

provide predefined element_length_fn for pipeline.bucket_boundaries #364

Merged
merged 4 commits into from
Nov 12, 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
9 changes: 8 additions & 1 deletion calamari_ocr/ocr/dataset/data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import os
from typing import Type, Optional
from typing import Callable, Dict, Type, Optional

import tensorflow as tf
from tfaip.util.tftyping import AnyTensor
from tfaip.data.data import DataBase
from tfaip.data.databaseparams import DataPipelineParams
from tfaip.data.pipeline.datapipeline import DataPipeline
Expand Down Expand Up @@ -84,6 +85,12 @@ def _target_layer_specs(self):
"gt_len": tf.TensorSpec([1], dtype=tf.int32),
}

def element_length_fn(self) -> Callable[[Dict[str, AnyTensor]], AnyTensor]:
def img_len(x):
return x["img_len"]

return img_len

def create_pipeline(
self,
pipeline_params: DataPipelineParams,
Expand Down
5 changes: 5 additions & 0 deletions calamari_ocr/test/test_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def test_dataset_prediction_voted(self):

predictor.benchmark_results.pretty_print()

def test_batch_bucketing(self):
args = predict_args()
args.predictor.pipeline.bucket_boundaries = [20, 50, 100, 200, 400, 800]
run(args)


if __name__ == "__main__":
unittest.main()
Loading