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

Show progress option for batch_recognition and batch_detection #144

Open
wants to merge 1 commit into
base: master
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
8 changes: 4 additions & 4 deletions surya/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_batch_size():
return batch_size


def batch_detection(images: List, model: SegformerForRegressionMask, processor, batch_size=None) -> Tuple[List[List[np.ndarray]], List[Tuple[int, int]]]:
def batch_detection(images: List, model: SegformerForRegressionMask, processor, batch_size=None, show_progress=True) -> Tuple[List[List[np.ndarray]], List[Tuple[int, int]]]:
assert all([isinstance(image, Image.Image) for image in images])
if batch_size is None:
batch_size = get_batch_size()
Expand All @@ -51,7 +51,7 @@ def batch_detection(images: List, model: SegformerForRegressionMask, processor,
batches.append(current_batch)

all_preds = []
for batch_idx in tqdm(range(len(batches)), desc="Detecting bboxes"):
for batch_idx in tqdm(range(len(batches)), desc="Detecting bboxes", disable=not show_progress):
batch_image_idxs = batches[batch_idx]
batch_images = convert_if_not_rgb([images[j] for j in batch_image_idxs])

Expand Down Expand Up @@ -122,8 +122,8 @@ def parallel_get_lines(preds, orig_sizes):
return result


def batch_text_detection(images: List, model, processor, batch_size=None) -> List[TextDetectionResult]:
preds, orig_sizes = batch_detection(images, model, processor, batch_size=batch_size)
def batch_text_detection(images: List, model, processor, batch_size=None, show_progress=True) -> List[TextDetectionResult]:
preds, orig_sizes = batch_detection(images, model, processor, batch_size=batch_size, show_progress=show_progress)
results = []
if settings.IN_STREAMLIT or len(images) < settings.DETECTOR_MIN_PARALLEL_THRESH: # Ensures we don't parallelize with streamlit, or with very few images
for i in range(len(images)):
Expand Down
4 changes: 2 additions & 2 deletions surya/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_batch_size():
return batch_size


def batch_recognition(images: List, languages: List[List[str]], model, processor, batch_size=None):
def batch_recognition(images: List, languages: List[List[str]], model, processor, batch_size=None, show_progress=True):
assert all([isinstance(image, Image.Image) for image in images])
assert len(images) == len(languages)

Expand Down Expand Up @@ -60,7 +60,7 @@ def batch_recognition(images: List, languages: List[List[str]], model, processor

processed_batches = processor(text=[""] * len(images), images=images, lang=languages)

for i in tqdm(range(0, len(images), batch_size), desc="Recognizing Text"):
for i in tqdm(range(0, len(images), batch_size), desc="Recognizing Text", disable=not show_progress):
batch_langs = languages[i:i+batch_size]
has_math = ["_math" in lang for lang in batch_langs]

Expand Down
Loading