Skip to content

Use trainer.predict for single images#1398

Open
jveitchmichaelis wants to merge 1 commit into
weecology:mainfrom
jveitchmichaelis:predict_lightning
Open

Use trainer.predict for single images#1398
jveitchmichaelis wants to merge 1 commit into
weecology:mainfrom
jveitchmichaelis:predict_lightning

Conversation

@jveitchmichaelis

@jveitchmichaelis jveitchmichaelis commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Description

Use the trainer for single image prediction, similar to other predict routes (predict_file).

We should probably use SingleImage, but this accepts a patch_size option which is not the behavior we had before. Here I've forced patch_size to be the same size as the image only in deepforest.predict_image which is a hack, but it doesn't change anything.

I've refactored _dataloader_wrapper_ for convenience and added crop_model support for single images. It now uses _crop_models_wrapper_ which has the same logic for multiple models.

There are some inconsistencies that we could look into - predict_file returns an empty dataframe for no predictions, while predict_tile and predict_image (previously and here) return None. Some prediction paths convert labels from int->str - plan to make everything consistent there?

Related Issue(s)

Would supersede and fix #1391

AI-Assisted Development

N/A

@jveitchmichaelis jveitchmichaelis changed the title use trainer.predict for single image Use trainer.predict for single images Jun 4, 2026
@jveitchmichaelis jveitchmichaelis force-pushed the predict_lightning branch 2 times, most recently from fc0ccd4 to a74e9c9 Compare June 4, 2026 23:41
@jveitchmichaelis jveitchmichaelis requested a review from bw4sz June 4, 2026 23:42
@jveitchmichaelis jveitchmichaelis marked this pull request as ready for review June 4, 2026 23:42
@jveitchmichaelis jveitchmichaelis force-pushed the predict_lightning branch 2 times, most recently from 9e91399 to ce18d68 Compare June 4, 2026 23:48
@jveitchmichaelis jveitchmichaelis removed the request for review from bw4sz June 5, 2026 00:15
@jveitchmichaelis jveitchmichaelis marked this pull request as draft June 5, 2026 00:15
@jveitchmichaelis jveitchmichaelis marked this pull request as ready for review June 5, 2026 00:19
@jveitchmichaelis

Copy link
Copy Markdown
Collaborator Author

Ready for review and we can address the inconsistency separately. For now this should fix the device placement bug.

@jveitchmichaelis jveitchmichaelis requested a review from bw4sz June 5, 2026 00:19
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.75758% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.26%. Comparing base (d2851ec) to head (77881cf).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/deepforest/predict.py 63.15% 7 Missing ⚠️
src/deepforest/main.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1398      +/-   ##
==========================================
- Coverage   86.61%   85.26%   -1.36%     
==========================================
  Files          26       27       +1     
  Lines        3736     3875     +139     
==========================================
+ Hits         3236     3304      +68     
- Misses        500      571      +71     
Flag Coverage Δ
unittests 85.26% <75.75%> (-1.36%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

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.

1 participant