Repository navigation
test: add CUDA regression coverage for predict_image (#1390) - #1442
hardikkaurani wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Hi @ethanwhite and @henrykironde, and thanks to @giswqs and @jveitchmichaelis for the related context. I’d appreciate your feedback on this small, test-only PR when time permits. It adds focused regression coverage for single-image CUDA inference, device alignment, and the trainer.predict path, without changing production code. The targeted local test run reported 5 passed and 1 skipped because CUDA was unavailable on that runner. Could you please let me know whether this test coverage fits the project’s expectations, or if you would prefer a narrower approach? I’m happy to address any review feedback. Thank you! |
…d array input (weecology#1390) - Wrap CUDA setup in nested try/finally to prevent session fixture leakage if trainer creation fails - Exercise both path and in-memory numpy array input modes on CUDA and alignment tests - Verify DataLoader dataset routing and avoid variable shadowing in trainer spy
Description
This PR adds regression test coverage for Issue #1390, where predict_image() failed during CUDA inference because the input tensor and model weights were on different devices.
Context
Issue #1390 reported a device mismatch during single-image inference when the detector was moved to CUDA:
Input type torch.FloatTensor and weight type torch.cuda.FloatTensor should be the same.PR #1398 addressed the runtime failure by routing predict_image() through SingleImage and trainer.predict. This PR adds focused regression coverage for that behavior in tests/test_main.py.
Changes
Added three targeted regression tests, with no production-code changes:
test_predict_image_on_cuda: Exercises predict_image() end-to-end when CUDA is available, skips on CPU-only environments, and restores CPU placement and trainer configuration in a finally block.test_predict_image_device_alignment: Uses a deterministic spy to verify that the batch tensor passed to the model is on the same device as the model parameters.test_predict_image_routes_through_trainer: Verifies that single-image prediction is dispatched through trainer.predict.Related issues and PRs
Related to #1390
Related to #1391
Related to #1398
Testing
Targeted local test run:
uv run pytest tests/test_main.py -k "test_predict_image"5 passed, 1 skipped
The skipped test requires CUDA, which was unavailable in the test environment. CUDA execution was therefore not verified by this local run.