Add MobileNet ONNX species classification and modernize BatBot - #44
Add MobileNet ONNX species classification and modernize BatBot#44bluemellophone wants to merge 10 commits into
Conversation
24d6f2e to
e6fe8b0
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #44 +/- ##
========================================
+ Coverage 59.2% 80.2% +20.9%
========================================
Files 7 14 +7
Lines 1383 1874 +491
Branches 0 251 +251
========================================
+ Hits 820 1504 +684
+ Misses 563 300 -263
- Partials 0 70 +70
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
| results_by_path[path] = {'path': path, 'error': str(error)} | ||
|
|
||
| wav_paths = [path for path in paths if Path(path).suffix.lower() in WAV_EXTENSIONS] | ||
| for path in tqdm.tqdm(wav_paths, disable=QUIET, desc='Classifying WAV files'): |
There was a problem hiding this comment.
Eventually, would be nice to allow parallel spec preprocessing here (using existing preprocessing functionality)
|
Looks great to me! Only other features I'd like would be 1) integrating the batch spec preprocessing into the batch ML inference, and 2) visual progress indicators in batch inference. Also, made a fresh install following these instructions but was unable to get it to use my gpu ("Failed to create CUDAExecutionProvider. Require cuDNN 9.* and CUDA 13.* ..."). Was the install expecting separate, manual install of CUDA and cuDNN? It seems like that shouldn't be necessary (link) - it's also possible something in my setup is different from yours. |
Summary
This PR prepares BatBot 0.2.0 by adding end-to-end bat-species classification with a bundled 35-label MobileNet ONNX model. Users can classify existing spectrograms, generate and classify spectrograms from WAV recordings, or process directory trees with fault-tolerant summaries and ordered multi-worker inference.
The PR also restructures the package so importing
batbotis lightweight, consolidates project configuration inpyproject.toml, raises the minimum Python version to 3.11, modernizes testing and publishing workflows, and expands branch coverage to 82.7%.High-level changes
pre/predict/postONNX inference pipeline and reusableClassifierpoochdownload mirror--num-workerswithout loading one model per workerclassify,classify-wav, andclassify-bulk; completedfetchand the legacybatchpathNOISEdiagnosticsbatbot.apiand added lazy submodule loadingimport batbotno longer initializes scientific/ONNX stacks or creates a log filepyproject.tomlModel and inference behavior
batbot.mobilenet.9dc57ea3.onnxthrough Git LFS and package data.poochcache.224 × 224 × 3windows.num_workers > 1runs per-spectrogram ONNX calls concurrently, preserves input order, bounds in-flight work, and reuses one session.spectrogram_outputor--spectrogram-dir.CLI changes
batbot fetch--pull,--configbatbot classify--batch-size,--num-workers,--top-k,--outputbatbot classify-wav--spectrogram-dir,--batch-size,--num-workers,--top-k,--outputbatbot classify-bulk--input-type,--recursive/--no-recursive,--spectrogram-dir,--num-workersbatbot batch--config,--num-workers,--outputClassification commands emit JSON containing individual results and a summary. The summary includes total, classified and failed counts, label counts, species counts excluding
NOISE, the noise count, and mean confidence.Performance plotting
examples/plot_classifier_performance.pynow accepts a folder hierarchy containing WAV, JPG, or JPEG inputs, including mixed datasets. The immediate parent directory remains the ground-truth label:The example supports reusable prediction caches and multi-worker inference. It produces count, true-normalized, and prediction-normalized confusion matrices; top-1/2/3/5 accuracy; Matthews correlation; and
NOISEprecision-recall, ROC, and operating-point diagnostics when applicable. Species are reordered by genus before plotting so the shaded error regions remain contiguous.API changes
New classifier API
batbot.classifier.Classifier(...)classifier.classify(inputs, ...)classifier.classify_wav(filepath, ...)classifier.classify_bulk(inputs, ...)classifier.fetch(pull=False, config=...)classifier.discover_inputs(...)classifier.summarize(results)classifier.pre,predict,postbatch_sizelimits the number of image windows sent in one ONNX call.num_workerscontrols the number of concurrent per-spectrogram inference jobs and defaults to1to avoid unexpected CPU oversubscription.Result contracts
pathlabelconfidencelabelwindow_counttopscoresspectrogram_pathsBulk failures use
{ "path": ..., "error": ... }and remain in input order alongside successful results.Existing top-level API
batbot.fetch()is now implemented and returns the resolved model path.batbot.batch()is now implemented, reuses a classifier session, and returns classification results. Itscleanargument remains accepted for compatibility; generated temporary spectrograms are always cleaned.batbot.pipeline(),pipeline_multi_wrapper(),parallel_pipeline(), andexample()moved tobatbot.apiand remain re-exported frombatbot.pipeline_multi_wrapper()andparallel_pipeline()now raiseValueErrorfor invalid lengths or worker counts instead of relying on assertions.VERSION,version, and__version__remain available, with_version.pyas the package metadata source.classifierandspectrogramare exposed lazily throughbatbot.__getattr__.Compatibility notes
requirements/*.txtbatbot,batbot[test],batbot[docs], orbatbot[performance]as appropriatebatbotlogger in the application or callbatbot.utils.init_logging()VERBOSE,CLASSIFIER_CONFIG, andCLASSIFIER_BATCH_SIZEremain supportedBATBOT_...-prefixed environment variablesbatchoutput is now real classifier outputChangelog
Added
NOISE.pooch.pull=True/--pull.pre/predict/postinference functions.Classifierwith ONNX session reuse and optional provider selection.classify,classify-wav, andclassify-bulkCLI commands.py.typedmarker.Removed
setup.py,setup.cfg,.flake8, and the three duplicatedrequirements/*.txtfiles.batbot.logside effect.BATBOT_PYPI_TOKENusage in the publishing workflow.Updated
0.2.0throughbatbot/_version.py.pyproject.toml.batbot.__init__to a small public facade with lazy computational submodules.batbot.apiwith explicit signatures and validation.fetchandbatchAPIs from placeholders to functional classifier entry points.docsextra.8.4.2, branch coverage configuration, random ordering, and focused classifier tests.Validation
twine check, installs the wheel outside the checkout, and performs model inferenceReviewer notes
Kitware, repositorybatbot, workflowpython-publish.yaml, and environmentpypibefore the first tagged release.1; concurrency is opt-in throughnum_workersor--num-workers.