Base¶
Base class for layout extractors.
Defines the abstract interface that all layout extractors must implement.
BaseLayoutExtractor
¶
Bases: ABC
Abstract base class for layout extractors.
All layout extraction models must inherit from this class and implement the required methods.
Example
extract
abstractmethod
¶
Run layout extraction on an image.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Input image as: - PIL.Image.Image: PIL image object - np.ndarray: Numpy array (HWC format, RGB) - str or Path: Path to image file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LayoutOutput
|
LayoutOutput containing detected layout boxes with standardized labels |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If image format is not supported |
RuntimeError
|
If model is not loaded or inference fails |
Source code in omnidocs/tasks/layout_extraction/base.py
batch_extract
¶
batch_extract(
images: List[Union[Image, ndarray, str, Path]],
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[LayoutOutput]
Run layout extraction on multiple images.
Default implementation loops over extract(). Subclasses can override for optimized batching.
| PARAMETER | DESCRIPTION |
|---|---|
images
|
List of images in any supported format
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[LayoutOutput]
|
List of LayoutOutput in same order as input |
Examples:
Source code in omnidocs/tasks/layout_extraction/base.py
extract_document
¶
extract_document(
document: Document,
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[LayoutOutput]
Run layout extraction on all pages of a document.
| PARAMETER | DESCRIPTION |
|---|---|
document
|
Document instance
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[LayoutOutput]
|
List of LayoutOutput, one per page |
Examples: