Skip to content

[WIP]: Improve predict_tile memory use and windowed raster inference #1304

Open
henrykironde wants to merge 7 commits intoweecology:mainfrom
henrykironde:fix-gpus
Open

[WIP]: Improve predict_tile memory use and windowed raster inference #1304
henrykironde wants to merge 7 commits intoweecology:mainfrom
henrykironde:fix-gpus

Conversation

@henrykironde
Copy link
Contributor

@henrykironde henrykironde commented Feb 14, 2026

Description

Related Issue(s)

AI-Assisted Development

  • I used AI tools (e.g., GitHub Copilot, ChatGPT, etc.) in developing this PR
  • I understand all the code I'm submitting
  • I have reviewed and validated all AI-generated code

AI tools used (if applicable):


Note

Medium Risk
Touches core inference data loading/normalization and raster IO lifecycle, which can affect prediction correctness and performance on large tiles. Added guards/tests reduce risk but edge cases around raster windowing and multiprocessing still warrant review.

Overview
Improves predict_tile/prediction datasets by making image preprocessing stricter and more consistent (shared RGB/CHW + dtype/range normalization) and preventing crop views from being mutated in-place (SingleImage.get_crop() now clones).

Hardens windowed raster inference (TiledRaster) by keeping a single raster handle open with explicit close()/pickle-safe reopen, warning (not failing) on non-tiled rasters, filtering/guarding against out-of-bounds/zero-size windows, and ensuring the handle is always closed via a try/finally in predict_tile.

Adds a warning when CUDA is available/requested but the Lightning Trainer isn’t actually using a GPU accelerator, plus new GPU/HPC-only regression tests for CUDA usage and multi-GPU DDP training; also bumps supported Python to <3.14.

Written by Cursor Bugbot for commit d847701. This will update automatically on new commits. Configure here.

- Add helper to convert inputs to RGB CHW float32 in [0, 1]
  - Validate ndim/channel placement and reject grayscale early
  - Normalize based on dtype (uint8 -> /255), not max/min heuristics
  - Ensure contiguous arrays before torch conversion
- Refactor SingleImage to keep full image in CHW without forcing full
  float32 copy; convert/normalize per-window crops in get_crop
- Improve TiledRaster/window strategy: reuse single rasterio handle,
  warn when untiled, close datasets promptly after predict
- Simplify predict_step return
- Warn when CUDA is available but trainer falls back to CPU
- Add test_gpu_inference_uses_cuda: regression test for GPU inference
- Add hpc_multi_gpu_train: DDP smoke test for multi-GPU training
- Relax requires-python to allow 3.13
@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 77.00000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (94af652) to head (d847701).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/deepforest/datasets/prediction.py 76.25% 19 Missing ⚠️
src/deepforest/main.py 80.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1304      +/-   ##
==========================================
- Coverage   87.16%   86.71%   -0.45%     
==========================================
  Files          21       21              
  Lines        2851     2914      +63     
==========================================
+ Hits         2485     2527      +42     
- Misses        366      387      +21     
Flag Coverage Δ
unittests 86.71% <77.00%> (-0.45%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy only when chw may alias the input (np.shares_memory), then use
in-place division. Preserves caller's data without memory spike from
regular division creating temporary arrays.

Co-authored-by: Cursor <cursoragent@cursor.com>
@henrykironde henrykironde changed the title Improve predict_tile memory use and windowed raster inference [WIP]: Improve predict_tile memory use and windowed raster inference Feb 15, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

… crops

Apply normalization to the entire image once before prediction.

Co-authored-by: Cursor <cursoragent@cursor.com>
@henrykironde henrykironde changed the title [WIP]: Improve predict_tile memory use and windowed raster inference Improve predict_tile memory use and windowed raster inference Feb 16, 2026
@jveitchmichaelis
Copy link
Collaborator

jveitchmichaelis commented Feb 16, 2026

@henrykironde how big of an image are you testing with here? I'll run some tests with memray on some NEON tiles if that'd help.

@henrykironde
Copy link
Contributor Author

@jveitchmichaelis I am using the orthos we created for Everglades. You can try with unprojected files in /blue/ewhite/everglades/orthomosaics/

i.e "/blue/ewhite/everglades/orthomosaics/2023/6thBridge/6thBridge_03_21_2023.tif" but I recommed that you work with a copy not the exact file

@henrykironde henrykironde changed the title Improve predict_tile memory use and windowed raster inference [WIP]: Improve predict_tile memory use and windowed raster inference Feb 25, 2026
@henrykironde
Copy link
Contributor Author

I need to test some edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants