You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds two new vectorized page level dataclasses:
- `TextRegions`: replaces a `list[TextRegion]` and store coordinates and
texts as numpy arrays for more efficient memory operations when the
number of items is large
- `LayoutElements`: replaces a `list[LayoutElement]` and store data in
numpy arrays as above
In addition this PR refactors `yolox` model inference to use those two
new classes above internally while keeping the list data structure still
available for backward compatibility (e.g., passing into a `PageLayout`
object).
## test
compare memory usage and runtime on a pdf image using
```python
from unstructured_inference.inference.layout import process_file_with_model
def main():
f = "/Users/yaoyou/Downloads/002489.pdf"
layout = process_file_with_model(f, model_name="yolox")
# replace elements_array with elements when using main branch
print(f"fount {len(layout.pages[0].elements_array)} elements")
if __name__ == "__main__":
main()
```
The peak memory is smaller on this branch (exact amount depends on the
number of layout elements detected) and processing time is slightly
faster (since this PR skips generation of list of `LayoutElement` from
numpy array output of the yolox model).
0 commit comments