[3/3] audioprotopnet: ConvNeXt + AudioProtoPNet + AudioProtoPNetSED models - #184
Open
nkundiushuti wants to merge 22 commits into
Open
[3/3] audioprotopnet: ConvNeXt + AudioProtoPNet + AudioProtoPNetSED models#184nkundiushuti wants to merge 22 commits into
nkundiushuti wants to merge 22 commits into
Conversation
…al losses, phase 2 in training with prototypical heads
Custom feature extractor returns Tensor, not BatchFeature dict. **-unpacking a Tensor raises TypeError. Inherited ConvNext forward passes process_audio result positionally — correct.
benjaminsshoffman
requested changes
May 15, 2026
- Replace sklearn train_test_split with esp_data PandasBackend in TrainValSplitTransform - Add worker_timeout param to build_dataloaders - Add birdset_train_splits module (registers birdset_train dataset) - Split ebird_taxonomy.json into v2021/v2025; load() now requires version arg - Add fill_labels_from_answer transform to beans benchmark configs - Rename birdset -> birdset_train in birdset benchmark configs - Add slurm benchmark config variants for beans
- Add _write_embedding_metadata helper; store aggregation in HDF5 attrs - HDF5EmbeddingDataset exposes embedding_aggregation attribute - _embedding_cache_matches validates aggregation before reuse - embedding_manager: use uncompressed size (shape*dtype) for memory routing - __getstate__ strips _window_cache to avoid N_workers x cache duplication - Window loads lazily on first __getitem__ (not prefilled in __init__) - _load_window scales capacity by num_workers to stay within budget
- Use _embedding_cache_matches for cache validation (aggregation-aware) - Fix operator precedence bugs in need_recompute_embeddings_*_clustering - Configurable offline probe embedding aggregation via probe_storage_aggregation - Hoist memory_limit_bytes before probing + retrieval/clustering branches - Graceful per-file fallback when embeddings missing (avoids base_model=None crash) - Release probe HDF5 caches before clustering to free ~46 GB - Reuse probe embeddings for retrieval/clustering when aggregation matches - Pass worker_timeout=120 to build_dataloaders
- Wire probe_num_workers (default 0) into all embedding DataLoaders - Gate pin_memory on probe_workers > 0 (pointless with no workers) - Fix multi-label target shape: one_hot 1D/squeezed-2D before BCEWithLogitsLoss
- Fix forward pass and feature extraction bugs - Remove example script (superseded by checkpoint configs) - Add beans evaluation config and slurm job
- Fix SED forward pass, feature extraction, and checkpoint loading bugs - Update audioprotopnet_sed checkpoint config - Add beans/birdset evaluation configs and slurm jobs
- BaseProbe2D._to_2d centralises 2D/3D/4D → 2D reduction logic
- _pool4d pools W/time dim of 4-D tensors (mean or max)
- input_processing param ('pooled'/'flatten'/'sequence') threads through all probe types
- Remove duplicated reshape branches across probes
- Export ESP_DATA_HOME=gs://esp-ml-datasets in all existing job scripts - Add setup_slurm_cuda124_venv.sh and sync_to_slurm.sh
This was referenced May 29, 2026
This was referenced May 29, 2026
Contributor
Author
|
This PR has been split into three parts to make review easier. #184 must be merged last.
Once #186 and #187 are merged into |
- transforms: add DataFrame path using iloc/unique for pandas compatibility; backend API path retained for esp_data Polars/other backends - pre-commit: narrow large-file and codespell excludes to ebird_taxonomy_v*.json; remove ruff/ruff-format avex/data/ exclude (ruff only targets Python anyway) - ebird_taxonomy: remove unused logger; fix FileNotFoundError docstring indent - birdset_train_splits: add missing Returns/Raises/Yields docstring sections - dataset: document worker_timeout param in build_dataloaders docstring - test_ebird_taxonomy: annotate version param as EbirdTaxonomyVersion
- embedding_utils: mark cache incomplete when batches were skipped; skipped rows leave unwritten gaps in pre-allocated HDF5 datasets - run_evaluate: _reuse_probe_embeddings_for_eval rejects aggregation=none (3D embeddings can't be fed into retrieval/clustering) - run_evaluate: replace path.exists() with _embedding_cache_matches for clustering cache; use pooled aggregation (mean/max) for the check
- tests: add heavy regression coverage for the BaseProbe3D 2-D-embedding semantic change (LSTM/attention/transformer end-to-end + shape primitives); locks in 'single timestep, full feature dim' over the old 'F scalar timesteps' - prototypical_utils: derive the dim-probing dummy length from the backbone audio config instead of hardcoding 32 kHz x 5 s - prototypical_utils: document that virtual 'last_layer' only exists on AudioProtoPNet(SED); ConvNeXt/EfficientNet fall back to base discovery - audioprotopnet: add trust_remote_code security warning and a revision param threaded through all HF load calls for pinning - audioprotopnet_sed: allocate the empty prototype_vectors placeholder only on the birdcode path (split path constructs it directly) - configs: include 'asl' in the multilabel loss validation message
…chable CI runs 'pytest tests/unittests' without -m 'not integration', so the @pytest.mark.integration SED test that pulls a checkpoint from a private GCS bucket ran anonymously and failed with a 401. Skip cleanly on any remote/auth/IO failure so the test only runs where the asset is reachable.
Contributor
Author
|
@benjaminsshoffman I removed the stage 2 part in run_train (as you suggested) and I left only the models and the evaluation part. |
Contributor
Author
|
@benjaminsshoffman let me know, @GaganNarula do you want to take a look as well? I just added these models to be able to benchmark them also the probe head, no training happens |
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.
Add ConvNeXt, AudioProtoPNet, AudioProtoPNet SED, prototype-based
classification, and two-stage training
New models
ConvNeXt (avex/models/convnext.py)
spectrogram input)
ConvNextCfg — no hardcoded constants
freeze/unfreeze during two-stage training
all existing probes
model._orig_mod.model. prefixes)
AudioProtoPNet (avex/models/audioprotopnet.py)
(DBD-research-group/AudioProtoPNet-{1,5,10,20}-BirdSet-XCL)
bundled eBird taxonomy)
AudioProtoPNet SED (avex/models/audioprotopnet_sed.py)
prototype head for sound event detection
max-pool only; temporal resolution ≈7.6 Hz at 32 kHz
gs://representation-learning/models/sed/audioprotopnet-20/ via
universal_torch_load (cached locally; same pattern as BEATs)
non-negative linear layer; weights initialised with kaiming_uniform
convnext_base.yml — no HuggingFace network calls beyond the checkpoint itself
Config
ConvNextCfg (avex/configs.py)
hop_length, n_mels, norm_mean, norm_std); defaults match BirdSet XCL training
setup
convnext_cfg block
_add_model_spec_params so user YAMLs flow through the factory correctly
eBird taxonomy (avex/data/)
all 9,736 BirdSet XCL species
New losses (avex/training/losses.py)
positives/negatives, probability margin clipping; registered as "asymmetric"
/ "asl" in build_criterion
orthogonal (‖P_c Pᵀ_c − I‖_F / numel)
Prototypical probe (avex/models/probes/prototypical_probe.py)
New "prototypical" probe type alongside linear, mlp, attention, lstm,
transformer
Architecture: cosine-similarity prototype layer → [0, 1] shift →
non-negative linear classifier
num_prototypes_per_class added to ProbeConfig
New "prototypical" probe type alongside linear, mlp, attention, lstm, transformer
Architecture: cosine-similarity prototype layer → [0, 1] shift → non-negative linear classifier
num_prototypes_per_class added to ProbeConfig
Example
examples/audioprotopnet_species_detection.py — clip-level and frame-level species detection on a directory of audio
files; --demo mode generates synthetic audio with no real recordings needed
Tests
registration, layer discovery)
activation, _LinearLayerWithoutNegativeConnections, registry)