Repository navigation
Conversation
Image/shape/form crops were cut from a second full-page PDFium render at scale 1. Derive that raster from the page render already made for the page-elements/OCR input instead (resize to page points, then the same rotation as before). The model input is unchanged. Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
[Medium impact] The PR appears safe to merge; no new actionable issue was found. SummaryThe PR reuses the page raster for PDF image crops instead of rendering each page twice.
|
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…raphIngestor Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…e-page-render Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
This comment has been minimized.
This comment has been minimized.
…made Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…111-single-page-render Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
With extract_images resolved off, native-text pages under pdfium_hybrid lost page_image, but page elements and OCR still read it on every page. Render whenever those stages run; only the crops stay skipped. Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…111-single-page-render Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
…111-single-page-render Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
extract_image_like_objects_from_pdfium_page takes page_image as an optional argument again; without it the page is rendered at scale 1 as before. Document its parameters and return value. Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
List the image, shape, and form options actually consumed by the box helpers.
|
Superseded by #2861, which batches the release fixes into one PR, one commit per original PR. This change is commit-for-commit identical there. |
|
Reopened: keeping the release fixes as individual PRs for review. #2861 is closed. |
|
Closing in favor of #2845, which includes this render-once change and also fixes crop placement on rotated and offset PDF pages. |
page_image is now keyword-only, so existing calls like extract_image_like_objects_from_pdfium_page(page, False) still bind merge. Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
| else: | ||
| points_size = (math.ceil(page_width), math.ceil(page_height)) | ||
| page_image_pts = np.rot90( | ||
| np.asarray(Image.fromarray(page_image).resize(points_size, Image.BILINEAR)), k=-(rotation // 90) |
There was a problem hiding this comment.
[P1] Keep the cached raster in the display frame fixed by #2845
For the requested order (#2845 first), page_image already has the PDF page rotation applied, and #2845 maps every crop box into that displayed frame. This additional np.rot90 turns the raster a second time, so the corrected boxes address the wrong pixels. I combined this actual cached-crop function with #2845's box helpers and real PDFium fixtures: the 270-degree crop is entirely blank instead of entirely image content; 90/180-degree crops are also wrong. The no-cache branch at line 628 likewise retains the extra rotation. Rebase this change onto #2845, resize the existing displayed raster without another turn, and have both paths use that same frame. Reuse #2845's correctness fixtures (including offset page boxes) in the single-render tests; their current reference renders with the old extra rotation and therefore cannot protect the earlier fix.
Crops cut from the page-element render now use #2845's displayed page frame: the render is only resized to points, with no extra rotation. The single-render tests compare against main's scale-1 render and expect a crop on every rotation. Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
|
Closing in favor of a fresh PR from main. As Julio found, this branch predates #2845 and rotates the cached page raster a second time, so 90/180/270-degree crops are wrong on top of #2845. The redo will reuse #2845's displayed-frame raster without another rotation and test against #2845's rotation and offset fixtures. |
There was a problem hiding this comment.
Devin Review found 1 finding. It is left for you to triage below.
| Crop boxes are in points in the displayed page frame. When ``page_image`` is | ||
| given, it is resized to the page size in points, so the boxes line up with a | ||
| ``page.render(scale=1)`` raster without rendering the page again. |
There was a problem hiding this comment.
🔍 PR summary describes an extra rotation
The PR summary says extract_image_like_objects_from_pdfium_page rotates the reused raster after resizing. Instead, _page_rect_to_display maps crop boxes into the orientation PDFium already rendered.
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Since #2841, crops are skipped by default; this PR makes the crop path render once when it does run (explicit
extract_images=True, caption, image store, explicit dedup). The default text and ViDoRe paths do not exercise it.pdf_extractionrendered every page twice whenextract_images=True: once at the model scale for the page-elements/OCRpage_image, and again inextract_image_like_objects_from_pdfium_pageat scale 1 just to cut image/shape/form crops. This PR renders once and cuts the crops from that same raster._render_page_to_base64is split into_render_page_rgb+_encode_page_imagesopdf_extractioncan keep the RGB array; the wrapper stays forimage_store.extract_image_like_objects_from_pdfium_page(page, page_image)takes that array instead of rendering. The rotation it applies is the same one the old second render applied.Results: pps flat, PDF-extraction CPU −5.7% when crops run
main vs this PR, bo10k (213,538 pages), 8 GPUs, BF16, same image, explicit
extract_images: true:b1c42dba9541c41c¹Rows are unchanged: 2 vs 4 unique (source, page, type) rows, which is OCR run-to-run noise.
¹ The eval ran on
9541c41c. Later commits only merge in #2841's review fixes andmain, which don't touch the crop path.Earlier measurements (older main, 2 GPUs)
PR vs main, measured with
extract_images=True, 2 runs each, A/B/B/A, same config, cold compile caches, 2 GPUsThese runs predate #2841, when
extract_images=Truewas the default, so they measure the crop path this PR now applies to.Ranges are min–max over 2 runs per arm, run order main, PR, PR, main per dataset. PDF extraction CPU is Ray Data's
pdf_extractionworker time divided by pages.Why it is safe
page_imageis encoded from the same render as before, so page elements and OCR see the same bytes. Crop boxes still come from PDF object positions.Tests
tests/test_pdf_single_render.py: rotations 0/90/180/270 at page sizes either side of the 1024 px fit (612x792, 2000x1500). Crop boxes and shapes equal the old native-render crops, pixels within 8/255 mean; onePdfPage.rendercall per page;page_imageequals_render_page_to_base64.tests/test_pdf_single_render.py tests/test_pdf_render_scale.py tests/test_caption.py tests/test_io_image_store.pyplus perf(extract): skip PDFium image crops when no stage reads them #2841'stests/ingestor,tests/ingest/test_service.py,tests/operators, andtests/test_ingest_manifest.py: 155 passed.Link to Devin session: https://nvidia-cloud.devinenterprise.com/sessions/57f5368b39844a038449e009f6bdd631
Open in Devin Desktop: https://nvidia-cloud.devinenterprise.com/desktop/session/57f5368b39844a038449e009f6bdd631?variant=devin
Requested by: @jioffe502
👀 1 finding for you to triage · Follow Devin's work