Repository navigation
Replace PytorchWildlife with sparrow-engine for MegaDetector cropping - #12
Open
Zhongqi Miao (zhmiao) wants to merge 5 commits into
Open
Zhongqi Miao (zhmiao) wants to merge 5 commits into
Zhongqi Miao (zhmiao) wants to merge 5 commits into
Conversation
…orchWildlife PytorchWildlife is retired, and a fresh install currently fails to import (the resolver picks yolov5 6.0.4, which lacks scale_boxes). Detection now calls sparrow_engine.detect and converts the normalized results to supervision.Detections so save_crop_images stays unchanged. The detector model and threshold are config keys (detector_model, detection_threshold); the default is MDV6-yolov10-e at 0.2. Only images listed in the annotation CSV are detected, and the cropped_resized output folder is never re-scanned. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b452684d-9b9b-4a61-9af9-28bddaabcf14
The old environment.yaml pinned Python 3.8, torch 1.10 and pytorchwildlife 1.0.1.1, none of which match requirements.txt. sparrow-engine needs Python 3.11+, so the env now installs requirements.txt on top of Python 3.11. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b452684d-9b9b-4a61-9af9-28bddaabcf14
Python 3.11+, the CPU/GPU sparrow-engine builds, the new detector_model and detection_threshold keys, and how trained weights are actually loaded (bundled loaders; sparrow-engine needs ONNX plus a manifest). Also corrects the CSV path examples: crops are matched by file name, so imgs/leopard_001.jpg never matched, and states that person and vehicle boxes are cropped too. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b452684d-9b9b-4a61-9af9-28bddaabcf14
…ting crops supervision >= 0.24 makes ImageSink.save_image raise FileExistsError when the crop already exists. Every non-predict run re-crops into the same cropped_resized folder, so a second run (for example --evaluate --val) crashed. PytorchWildlife had pinned supervision 0.23, which overwrote silently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b452684d-9b9b-4a61-9af9-28bddaabcf14
…ects main.py writes the split CSVs next to split_path and reads them from dataset_root, so the layout with the CSV outside imgs/ could not work. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b452684d-9b9b-4a61-9af9-28bddaabcf14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PytorchWildlife is retired, and a fresh
pip install -r requirements.txtno longer imports: the resolver picksyolov5==6.0.4, and PytorchWildlife 1.3.1 then fails withImportError: cannot import name 'scale_boxes' from 'yolov5.utils.general'. PytorchWildlife was used only for the MegaDetector cropping step (src/utils/batch_detection_cropping.py).What
batch_detection_cropping.pycallssparrow_engine.detectand converts results tosupervision.Detectionsin pixelxyxy, sosave_crop_imagesis unchanged.dataset_root, including thecropped_resized/output folder.detector_model(defaultMDV6-yolov10-e, downloaded on first use) anddetection_threshold(default0.2, the old value).requirements.txt:sparrow-enginereplacesPytorchWildlife. Packages PytorchWildlife used to pull in transitively are now listed explicitly: timm, supervision, pandas, Pillow, tqdm, wget and opencv-python-headless.environment.yaml: the stale Python 3.8 / torch 1.10 export is replaced with Python 3.11 plus-r requirements.txt.src.models.classificationloaders. Running them in sparrow-engine needs ONNX export plus a manifest; this PR does not add an exporter.pathexamples are corrected. Crops are matched by file name, soimgs/leopard_001.jpgnever matched.Behaviour changes
MDV6-yolov10-e): MDv5a is link-only in the sparrow-engine zoo, so it can't be auto-downloaded. On the test set below, MDv6 gives 250 crops vs 257. Users with MDv5a installed locally can setdetector_model: MDV5a. MDv6-yolov10-e is AGPL-3.0 upstream, and the docs say so.sparrow-enginewheel. Usesparrow-engine-gpufor CUDA detection. Training still uses torch and--gpus.Verification
I couldn't use the Zenodo demo data from the test machine (HTTP 403), so I used 100 local camera-trap JPGs: 50 train and 50 val, with dummy two-class labels.
detector_model: MDV5aMDV6-yolov10-eEnd-to-end, a fresh Python 3.11 venv with only this
requirements.txt(no PytorchWildlife) ranpython main.pyfor 1 epoch: it detected, cropped, trained and saved a checkpoint, exiting 0.mkdocs build --strictpasses.Related
This supersedes the dependency workaround in #8 (soundfile, librosa and
setuptools<82were needed only by PytorchWildlife's imports).Not changed here: crops include
personandvehicleboxes, each labelled with the image's species. That was the old behaviour too, and it is now documented. Restricting crops to animals would be a separate change.End-to-end test (fresh clone, clean Python 3.11 venv, no PytorchWildlife)
100 camera-trap images, 2 classes, 10 locations,
split_type: location, 2 epochs.python main.py(split, MDv6 auto-download, crop, train)--evaluate <ckpt> --test--evaluate <ckpt> --valFileExistsError)--evaluate <ckpt> --predict --predict-root data/imgspython main.pyover existing cropssparrow-engine-gpuinstead ofsparrow-engineactive_device()=cuda:0, same test accuracy (77 vs 76 test crops)Fixes found by the test:
supervisionraisesFileExistsErrorinImageSinkfor crops that already exist, so any second run crashed. PytorchWildlife had pinnedsupervision==0.23.0. Crops are now written withcv2.imwrite.imgs/, butmain.pywrites the splits next tosplit_pathand reads them fromdataset_root. The docs now matchconfig.yaml.Notes:
main.py:58-59(gpus=None). fix: load configs with yaml.safe_load and validate the GPU list #7 fixes that; merge it as well.pip install -r requirements.txtgets the default PyPI torch (CUDA 13.x build). On a host whose driver only supports CUDA 12.x, install torch from the matching index (for example--index-url https://download.pytorch.org/whl/cu128). The old requirements had the same behaviour.