Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lolipopshock
Copy link
Collaborator

@lolipopshock lolipopshock commented Jun 25, 2022

This PR introduces a new function in the VILA predictors predict_page that allows setting the maximum batch size for running the model. This can be used to control the memory usage when using the vial models.

@lolipopshock
Copy link
Collaborator Author

The current batching function is tested via:

import vila 
import layoutparser as lp # For visualization 

from vila.pdftools.pdf_extractor import PDFExtractor
from vila.predictors import HierarchicalPDFPredictor, LayoutIndicatorPDFPredictor

pdf_extractor = PDFExtractor("pdfplumber")
page_tokens, page_images = pdf_extractor.load_tokens_and_image("test.pdf")

vision_model = lp.EfficientDetLayoutModel("lp://PubLayNet") 
pdf_predictor = LayoutIndicatorPDFPredictor.from_pretrained("allenai/ivila-block-layoutlm-finetuned-docbank")
for idx, page_token in enumerate(page_tokens):
    blocks = vision_model.detect(page_images[idx])
    page_token.annotate(blocks=blocks)
    pdf_data = page_token.to_pagedata().to_dict()
    predicted_tokens = pdf_predictor.predict(pdf_data, page_token.page_size)
    predicted_tokens2 = pdf_predictor.predict_page(pdf_data, page_token.page_size, 1)
    assert predicted_tokens == predicted_tokens2

@lolipopshock lolipopshock merged commit 4dc60ae into master Jun 27, 2022
@lolipopshock lolipopshock deleted the control-predict-batch branch June 29, 2022 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants