### Install PaSST and PyTorch Source: https://context7.com/kkoutini/passt_hear21/llms.txt Install the hear21passt library and the required PyTorch and torchaudio versions. CUDA 11.1 is tested. ```bash pip install hear21passt # Required: PyTorch + torchaudio (CUDA 11.1 tested) pip3 install torch==1.8.1+cu111 torchaudio==0.8.1 \ -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html ``` -------------------------------- ### Install PaSST Package Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Install the latest version of the PaSST package using pip. ```shell pip install hear21passt ``` -------------------------------- ### Install PyTorch with CUDA 11.1 Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Install PyTorch and torchaudio compatible with CUDA 11.1. This is the tested version, but newer versions may also work. ```shell pip3 install torch==1.8.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html ``` -------------------------------- ### Getting Logits with Specific Architecture Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Demonstrates loading a specific pre-trained model architecture for obtaining logits. ```APIDOC ## Getting Logits with Specific Architecture ### Description Loads a specific pre-trained model architecture (e.g., `passt_s_kd_p16_128_ap486`) to get logits. ### Method ```python from hear21passt.base import get_basic_model model = get_basic_model(mode="logits", arch="passt_s_kd_p16_128_ap486") logits = model(wave_signal) ``` ``` -------------------------------- ### Loading Other Pre-trained Models Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Provides examples of loading various pre-trained models for different tasks like classification or fine-tuning, specifying architectures and number of classes. ```APIDOC ## Loading Other Pre-trained Models ### Description Loads different pre-trained models for logits or fine-tuning, specifying architectures and configurations. ### Method ```python import torch from hear21passt.base import get_basic_model, get_model_passt model = get_basic_model(mode="logits") logits = model(some_wave_signal) # Examples of other pre-trained models using the same spectrograms # pre-trained on openMIC-18 model.net = get_model_passt(arch="openmic", n_classes=20) # pre-trained on FSD-50k model.net = get_model_passt(arch="fsd50k", n_classes=200) # pre-trained on FSD-50k without patch-overlap (faster) model.net = get_model_passt(arch="fsd50k-n", n_classes=200, fstride=16, tstride=16) # models are trained on 10 seconds audios from Audioset, but accept longer audios (20s, or 30s) # These models are trained by sampling a 10-second time-pos-encodings sequence model.net = get_model_passt("passt_20sec", input_tdim=2000) model.net = get_model_passt("passt_30sec", input_tdim=3000) ``` ``` -------------------------------- ### Get Logits for AudioSet Classes Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Load a PaSST model configured to output logits (before sigmoid activation) for the 527 AudioSet classes. The input `wave_signal` should be a PyTorch tensor. ```python from hear21passt.base import load_model model = load_model(mode="logits").cuda() logits = model(wave_signal) ``` -------------------------------- ### Getting Logits/Class Labels Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Shows how to load a model in 'logits' mode to obtain raw class predictions before sigmoid activation. ```APIDOC ## Getting Logits/Class Labels ### Description Obtains logits (pre-sigmoid activation) for 527 audioset classes. ### Method ```python from hear21passt.base import load_model model = load_model(mode="logits").cuda() logits = model(wave_signal) ``` ``` -------------------------------- ### Construct Customizable PaSST Model Source: https://context7.com/kkoutini/passt_hear21/llms.txt Builds a customizable PaSST wrapper without GPU placement. Allows swapping the backbone, for example, to a knowledge-distillation trained model. The model is then moved to CUDA and set to evaluation mode. ```python import torch from hear21passt.base import get_basic_model, get_model_passt # Default backbone: passt_s_swa_p16_128_ap476 model = get_basic_model(mode="logits") # Swap backbone to knowledge-distillation trained model (mAP=0.486) model.net = get_model_passt(arch="passt_s_kd_p16_128_ap486") model = model.cuda().eval() wave = torch.randn(1, 32000 * 10).cuda() with torch.no_grad(): logits = model(wave) # (1, 527) probs = logits.sigmoid() top5 = probs[0].topk(5) print("Top-5 AudioSet class indices:", top5.indices.tolist()) print("Top-5 probabilities:", top5.values.tolist()) ``` -------------------------------- ### Get Logits with KD-Trained Model Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Load a specific pre-trained model ('passt_s_kd_p16_128_ap486') using `get_basic_model` to obtain logits. This model is trained with knowledge distillation. ```python from hear21passt.base import get_basic_model model = get_basic_model(mode="logits", arch="passt_s_kd_p16_128_ap486") logits = model(wave_signal) ``` -------------------------------- ### Load and Configure PaSST Models Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Demonstrates loading a base model and then reconfiguring its network component (`net`) with different pre-trained architectures (e.g., openMIC, FSD-50k) and input configurations. Ensure `input_tdim`, `fstride`, and `tstride` match the chosen model's requirements to avoid silent failures. ```python import torch from hear21passt.base import get_basic_model, get_model_passt model = get_basic_model(mode="logits") logits = model(some_wave_signal) # Examples of other pre-trained models using the same spectrograms # pre-traind on openMIC-18 model.net = get_model_passt(arch="openmic", n_classes=20) # pre-traind on FSD-50k model.net = get_model_passt(arch="fsd50k", n_classes=200) # pre-traind on FSD-50k without patch-overlap (faster) model.net = get_model_passt(arch="fsd50k-n", n_classes=200, fstride=16, tstride=16) # models are trained on 10 seconds audios from Audioset, but accept longer audios (20s, or 30s) # These models are trained by sampling a 10-second time-pos-encodings sequence model.net = get_model_passt("passt_20sec", input_tdim=2000) model.net = get_model_passt("passt_30sec", input_tdim=3000) ``` -------------------------------- ### Initialize PasstBasicWrapper for Sliding-Window Inference Source: https://context7.com/kkoutini/passt_hear21/llms.txt Initializes the AugmentMelSTFT frontend and PaSST backbone, then wraps them in PasstBasicWrapper for efficient sliding-window inference. Configure temporal parameters like max_model_window, timestamp_window, timestamp_hop, and scene_hop to control how audio is processed. ```python import torch from hear21passt.models.passt import get_model as get_model_passt from hear21passt.models.preprocess import AugmentMelSTFT from hear21passt.wrapper import PasstBasicWrapper mel = AugmentMelSTFT(n_mels=128, sr=32000, win_length=800, hopsize=320, n_fft=1024, freqm=0, timem=0, # no augmentation fmin=0.0, fmax=16000, norm=1, fmin_aug_range=1, fmax_aug_range=1) net = get_model_passt(arch="passt_s_kd_p16_128_ap486") model = PasstBasicWrapper( mel=mel, net=net, mode="all", max_model_window=10000, # max 10 s per forward pass timestamp_window=160, # 160 ms embedding windows timestamp_hop=50, # 50 ms hop scene_hop=2500, # 2.5 s hop for scene aggregation scene_embedding_size=1295, timestamp_embedding_size=1295, ) model.eval() audio = torch.randn(1, 32000 * 12) # 12 s clip → triggers windowed scene embed with torch.no_grad(): scene_emb = model.get_scene_embeddings(audio) ts_emb, ts = model.get_timestamp_embeddings(audio) print(scene_emb.shape) # torch.Size([1, 1295]) print(ts_emb.shape) # torch.Size([1, n_timestamps, 1295]) ``` -------------------------------- ### Loading and Using Base Model Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Demonstrates how to load the base PaSST model and extract scene and timestamp embeddings from audio data. ```APIDOC ## Loading and Using Base Model ### Description Loads the base PaSST model and extracts embeddings. ### Method ```python from hear21passt.base import load_model, get_scene_embeddings, get_timestamp_embeddings model = load_model().cuda() seconds = 15 audio = torch.ones((3, 32000 * seconds))*0.5 embed, time_stamps = get_timestamp_embeddings(audio, model) print(embed.shape) embed = get_scene_embeddings(audio, model) print(embed.shape) ``` ``` -------------------------------- ### Supporting Longer Clips (20/30 seconds) Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Illustrates how to load models specifically designed to handle audio clips longer than 10 seconds. ```APIDOC ## Supporting Longer Clips (20/30 seconds) ### Description Loads models capable of processing audio clips up to 20 or 30 seconds without averaging. ### Method ```python # For up to 20 seconds of audio from hear21passt.base20sec import load_model as load_model_20sec model_20sec = load_model_20sec(mode="logits").cuda() logits_20sec = model_20sec(wave_signal) # For up to 30 seconds of audio from hear21passt.base30sec import load_model as load_model_30sec model_30sec = load_model_30sec(mode="logits").cuda() logits_30sec = model_30sec(wave_signal) ``` ``` -------------------------------- ### Load High-resolution AudioSet Model Source: https://context7.com/kkoutini/passt_hear21/llms.txt Instantiates a PaSST Vision Transformer with high-resolution AudioSet pre-trained weights. Ensure the AugmentMelSTFT configuration is compatible to avoid silent degradation. The model is moved to CUDA and set to evaluation mode. ```python from hear21passt.models.passt import get_model as get_model_passt from hear21passt.models.preprocess import AugmentMelSTFT from hear21passt.wrapper import PasstBasicWrapper import torch # High-resolution AudioSet model (STFT hop=100 → 3200 time frames for 10 s) net = get_model_passt(arch="stfthop100", input_tdim=3200) mel = AugmentMelSTFT( n_mels=128, sr=32000, win_length=800, hopsize=100, n_fft=1024, freqm=48, timem=192, htk=False, fmin=0.0, fmax=None, norm=1, fmin_aug_range=10, fmax_aug_range=2000 ) model = PasstBasicWrapper(mel=mel, net=net, mode="logits").cuda().eval() wave = torch.randn(1, 32000 * 10).cuda() with torch.no_grad(): logits = model(wave) # (1, 527) print(logits.shape) ``` -------------------------------- ### Load OpenMIC-2008 Instrument Classification Model Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads a PaSST model fine-tuned on OpenMIC-2008 for 20-class instrument recognition. The output embeddings concatenate transformer features with 20-class logits. Ensure audio is mono at 32 kHz with values in [-1, 1]. ```python import torch from hear21passt.openmic2008 import load_model, get_scene_embeddings model = load_model(mode="all").cuda() # mono audio at 32 kHz, values in [-1, 1] audio = torch.randn(4, 32000 * 10).clamp(-1, 1).cuda() embed = get_scene_embeddings(audio, model) print(embed.shape) # torch.Size([4, 788]) # 768 features + 20 class logits ``` -------------------------------- ### Configure AugmentMelSTFT for Pretrained Model Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Sets up the AugmentMelSTFT layer with specific parameters for a pretrained model. Ensure hopsize is set to 100 for this model. ```python model.mel = AugmentMelSTFT(n_mels=128, sr=32000, win_length=800, hopsize=100, n_fft=1024, freqm=48, timem=192, htk=False, fmin=0.0, fmax=None, norm=1, fmin_aug_range=10, fmax_aug_range=2000) ``` -------------------------------- ### Configure High-Resolution Spectrograms Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Load models requiring specific high-resolution spectrogram configurations, such as `stfthop160` and `stfthop100`. This involves setting the correct `input_tdim` and instantiating `AugmentMelSTFT` with matching parameters like `hopsize`. ```python from hear21passt.models.preprocess import AugmentMelSTFT # high-res pre-trained on Audioset model.net = get_model_passt("stfthop160", input_tdim=2000) # hopsize=160 for this pretrained model model.mel = AugmentMelSTFT(n_mels=128, sr=32000, win_length=800, hopsize=160, n_fft=1024, freqm=48, timem=192, htk=False, fmin=0.0, fmax=None, norm=1, fmin_aug_range=10, fmax_aug_range=2000) # higher-res pre-trained on Audioset model.net = get_model_passt("stfthop100", input_tdim=3200) ``` -------------------------------- ### get_basic_model Source: https://context7.com/kkoutini/passt_hear21/llms.txt Constructs a customizable PaSST wrapper model without automatic GPU placement. Allows swapping the pre-trained backbone. ```APIDOC ## get_basic_model ### Description Builds a `PasstBasicWrapper` with a configurable architecture and mode, without GPU placement. Allows swapping in any pre-trained backbone via `model.net = get_model_passt(...)` after construction. ### Method `get_basic_model(mode: str = "all", arch: str = "passt_s_swa_p16_128_ap476") -> PasstBasicWrapper` ### Parameters #### Query Parameters - **mode** (str) - Optional - Controls the forward-pass output. Options: `"all"`, `"embed_only"`, `"logits"`. - **arch** (str) - Optional - The architecture of the backbone model to load. Defaults to `"passt_s_swa_p16_128_ap476"`. ### Request Example ```python import torch from hear21passt.base import get_basic_model, get_model_passt # Default backbone: passt_s_swa_p16_128_ap476 model = get_basic_model(mode="logits") # Swap backbone to knowledge-distillation trained model (mAP=0.486) model.net = get_model_passt(arch="passt_s_kd_p16_128_ap486") model = model.cuda().eval() wave = torch.randn(1, 32000 * 10).cuda() with torch.no_grad(): logits = model(wave) # (1, 527) probs = logits.sigmoid() top5 = probs[0].topk(5) print("Top-5 AudioSet class indices:", top5.indices.tolist()) print("Top-5 probabilities:", top5.values.tolist()) ``` ### Response #### Success Response (PasstBasicWrapper) - Returns a customizable PaSST model wrapper instance. ``` -------------------------------- ### load_model (openmic2008) Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads a PaSST model fine-tuned on OpenMIC-2008 for instrument classification. It provides scene and timestamp embeddings combined with 20-class logits. ```APIDOC ## `load_model` (openmic2008) — OpenMIC-2008 instrument classification model ### Description Loads a PaSST model fine-tuned on OpenMIC-2008 for 20-class instrument recognition. Scene and timestamp embeddings concatenate transformer features with 20-class logits, yielding 788-dimensional vectors (`768 + 20`). ### Usage Example ```python import torch from hear21passt.openmic2008 import load_model, get_scene_embeddings model = load_model(mode="all").cuda() # mono audio at 32 kHz, values in [-1, 1] audio = torch.randn(4, 32000 * 10).clamp(-1, 1).cuda() embed = get_scene_embeddings(audio, model) print(embed.shape) # torch.Size([4, 788]) # 768 features + 20 class logits ``` ``` -------------------------------- ### Generate Scene and Timestamp Embeddings Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Load the base PaSST model and generate scene and timestamp embeddings for a given audio signal. Ensure the audio tensor is on the CUDA device. ```python import torch from hear21passt.base import load_model, get_scene_embeddings, get_timestamp_embeddings model = load_model().cuda() seconds = 15 audio = torch.ones((3, 32000 * seconds))*0.5 embed, time_stamps = get_timestamp_embeddings(audio, model) print(embed.shape) embed = get_scene_embeddings(audio, model) print(embed.shape) ``` -------------------------------- ### Load PaSST Model for AudioSet Classification Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads a pre-trained PaSST wrapper model. The default mode returns concatenated logits and features. Use 'logits' mode for AudioSet 527-class classification. The model is automatically moved to GPU if CUDA is available. Ensure the model is in evaluation mode. ```python from hear21passt.base import load_model # Default mode="all" → forward returns (logits + features) concatenated model = load_model() # Logits-only mode for AudioSet 527-class classification model = load_model(mode="logits") model.eval() import torch wave = torch.randn(2, 32000 * 5) # batch of 2, 5-second clips at 32 kHz wave = wave.cuda() with torch.no_grad(): logits = model(wave) # shape: (2, 527) print(logits.shape) # torch.Size([2, 527]) print(logits.sigmoid()) # class probabilities for 527 AudioSet categories ``` -------------------------------- ### load_model (base20sec / base30sec) Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads PaSST variants pre-trained with extended time encodings (20 or 30 seconds), enabling embedding extraction over longer clips. The `scene_hop` parameter controls overlap for audio exceeding the model's window. ```APIDOC ## `load_model` (base20sec / base30sec) — Models with extended time encodings ### Description Loads a PaSST variant pre-trained with 20- or 30-second positional encodings, enabling embedding extraction over longer clips without per-window averaging. The `scene_hop` parameter (ms) controls overlap when the audio exceeds the model's extended window. ### Usage Example ```python import torch # 20-second model from hear21passt.base20sec import load_model, get_scene_embeddings, get_timestamp_embeddings model = load_model(mode="logits", scene_hop=5000).cuda() # 5 s scene hop audio = torch.randn(2, 32000 * 25) # 25-second clips; exceeds 20 s → windowed embed = get_scene_embeddings(audio, model) print(embed.shape) # torch.Size([2, 1295]) # 30-second model from hear21passt.base30sec import load_model as load_model_30 model30 = load_model_30(mode="all").cuda() embeddings, timestamps = get_timestamp_embeddings(audio, model30) print(embeddings.shape) # torch.Size([2, n_timestamps, 1295]) ``` ``` -------------------------------- ### Load PaSST Models with Extended Time Encodings Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads PaSST variants pre-trained with 20- or 30-second positional encodings for longer audio clips. The `scene_hop` parameter controls overlap for audio exceeding the model's window. Use `get_scene_embeddings` for 20-second models and `get_timestamp_embeddings` for 30-second models. ```python import torch # 20-second model from hear21passt.base20sec import load_model, get_scene_embeddings, get_timestamp_embeddings model = load_model(mode="logits", scene_hop=5000).cuda() # 5 s scene hop audio = torch.randn(2, 32000 * 25) # 25-second clips; exceeds 20 s → windowed embed = get_scene_embeddings(audio, model) print(embed.shape) # torch.Size([2, 1295]) # 30-second model from hear21passt.base30sec import load_model as load_model_30 model30 = load_model_30(mode="all").cuda() embeddings, timestamps = get_timestamp_embeddings(audio, model30) print(embeddings.shape) # torch.Size([2, n_timestamps, 1295]) ``` -------------------------------- ### Load Models for Longer Clips Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Import and load specific model variants designed to handle audio clips longer than 10 seconds (up to 20 or 30 seconds) without averaging embeddings. These models have pre-trained time positional encodings. ```python # from version 0.0.18, it's possible to use: from hear21passt.base20sec import load_model # up to 20 seconds of audio. # or from hear21passt.base30sec import load_model # up to 30 seconds of audio. model = load_model(mode="logits").cuda() logits = model(wave_signal) ``` -------------------------------- ### Validate PaSST Models Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Use the hear-validator to check the functionality of different PaSST modules. This requires downloading model weights separately for some variants. ```shell hear-validator --model hear21passt.base.pt hear21passt.base ``` ```shell hear-validator --model noweights.txt hear21passt.base2levelF ``` ```shell hear-validator --model noweights.txt hear21passt.base2levelmel ``` -------------------------------- ### High-Resolution Spectrogram Models Source: https://github.com/kkoutini/passt_hear21/blob/main/README.md Details on loading models that require specific spectrogram configurations, such as higher resolutions or different hop sizes. ```APIDOC ## High-Resolution Spectrogram Models ### Description Loads models requiring specific spectrogram configurations, like higher resolutions or custom hop sizes. ### Method ```python import torch from hear21passt.models.preprocess import AugmentMelSTFT # high-res pre-trained on Audioset model.net = get_model_passt("stfthop160", input_tdim=2000) # hopsize=160 for this pretrained model model.mel = AugmentMelSTFT(n_mels=128, sr=32000, win_length=800, hopsize=160, n_fft=1024, freqm=48, timem=192, htk=False, fmin=0.0, fmax=None, norm=1, fmin_aug_range=10, fmax_aug_range=2000) # higher-res pre-trained on Audioset model.net = get_model_passt("stfthop100", input_tdim=3200) ``` ``` -------------------------------- ### AugmentMelSTFT Source: https://context7.com/kkoutini/passt_hear21/llms.txt A differentiable PyTorch module for converting raw waveforms to log-Mel spectrograms, featuring SpecAugment-style data augmentation (frequency and time masking) during training and disabling augmentation during evaluation. ```APIDOC ## `AugmentMelSTFT` — Mel spectrogram extractor with frequency/time masking ### Description Differentiable PyTorch module that converts raw waveforms to log-Mel spectrograms. During training applies frequency masking (`freqm`) and time masking (`timem`) for SpecAugment-style data augmentation, and optionally randomizes `fmin`/`fmax` boundaries. Evaluation mode disables augmentation. ### Usage Example ```python import torch from hear21passt.models.preprocess import AugmentMelSTFT mel = AugmentMelSTFT( n_mels=128, sr=32000, win_length=800, hopsize=320, # default → ~998 frames for 10-s clip n_fft=1024, freqm=48, # max frequency mask width (bins) timem=192, # max time mask width (frames) fmin=0.0, fmax=None, # auto-set to sr/2 − fmax_aug_range/2 fmin_aug_range=10, fmax_aug_range=2000, ) mel.eval() # disable augmentation wave = torch.randn(2, 32000 * 10) # batch of 2 clips spec = mel(wave) print(spec.shape) # torch.Size([2, 128, ~998]) — (batch, mel_bins, time_frames) print(spec.min().item(), spec.max().item()) # roughly normalized around 0 ``` ``` -------------------------------- ### load_model Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads a pre-trained PaSST wrapper model. This function can automatically move the model to GPU if CUDA is available. The 'mode' parameter controls the forward-pass output, supporting 'all' (logits + features), 'embed_only' (transformer features), and 'logits' (raw class logits). ```APIDOC ## load_model ### Description Loads a `PasstBasicWrapper` combining a Mel-STFT frontend and a pre-trained PaSST transformer. Automatically moves the model to GPU if CUDA is available. The `mode` parameter controls forward-pass output: `"all"` returns concatenated logits + features, `"embed_only"` returns transformer features only, and `"logits"` returns raw class logits (before sigmoid) for the 527 AudioSet classes. ### Method `load_model(mode: str = "all") -> PasstBasicWrapper` ### Parameters #### Query Parameters - **mode** (str) - Optional - Controls the forward-pass output. Options: `"all"`, `"embed_only"`, `"logits"`. ### Request Example ```python from hear21passt.base import load_model # Default mode="all" → forward returns (logits + features) concatenated model = load_model() # Logits-only mode for AudioSet 527-class classification model = load_model(mode="logits") model.eval() import torch wave = torch.randn(2, 32000 * 5) # batch of 2, 5-second clips at 32 kHz wave = wave.cuda() with torch.no_grad(): logits = model(wave) # shape: (2, 527) print(logits.shape) # torch.Size([2, 527]) print(logits.sigmoid()) # class probabilities for 527 AudioSet categories ``` ### Response #### Success Response (PasstBasicWrapper) - Returns a PaSST model wrapper instance. ``` -------------------------------- ### Extract Timestamp Embeddings with PaSST Source: https://context7.com/kkoutini/passt_hear21/llms.txt Extracts frame-level (timestamp) embeddings by sliding a window across the waveform. Returns embeddings and their center timestamps in milliseconds. Output shapes are (n_sounds, n_timestamps, embedding_size) and (n_sounds, n_timestamps). ```python import torch from hear21passt.base import load_model, get_timestamp_embeddings model = load_model().cuda() audio = torch.ones((2, 32000 * 10)) * 0.5 # 2 sounds, 10 seconds each embeddings, timestamps = get_timestamp_embeddings(audio, model) print(embeddings.shape) # torch.Size([2, n_timestamps, 1295]) print(timestamps.shape) # torch.Size([2, n_timestamps]) print(timestamps[0, :5]) # center timestamps in ms, e.g. [0, 50, 100, 150, 200] ``` -------------------------------- ### get_model_passt Source: https://context7.com/kkoutini/passt_hear21/llms.txt Loads a specific pre-trained transformer backbone for PaSST. This is a low-level factory function that requires compatible AugmentMelSTFT configuration. ```APIDOC ## `get_model_passt` — Load a specific pre-trained transformer backbone ### Description Low-level factory that instantiates a `PaSST` Vision Transformer with the chosen pre-trained weights and spectrogram configuration. Must be paired with a compatible `AugmentMelSTFT` configuration — mismatches produce silent degradation. ### Usage Example ```python from hear21passt.models.passt import get_model as get_model_passt from hear21passt.models.preprocess import AugmentMelSTFT from hear21passt.wrapper import PasstBasicWrapper import torch # High-resolution AudioSet model (STFT hop=100 → 3200 time frames for 10 s) net = get_model_passt(arch="stfthop100", input_tdim=3200) mel = AugmentMelSTFT( n_mels=128, sr=32000, win_length=800, hopsize=100, n_fft=1024, freqm=48, timem=192, htk=False, fmin=0.0, fmax=None, norm=1, fmin_aug_range=10, fmax_aug_range=2000 ) model = PasstBasicWrapper(mel=mel, net=net, mode="logits").cuda().eval() wave = torch.randn(1, 32000 * 10).cuda() with torch.no_grad(): logits = model(wave) # (1, 527) print(logits.shape) ``` ``` -------------------------------- ### AugmentMelSTFT for Mel Spectrogram Extraction Source: https://context7.com/kkoutini/passt_hear21/llms.txt A differentiable PyTorch module for converting raw waveforms to log-Mel spectrograms. During training, it applies frequency and time masking for data augmentation. Evaluation mode disables augmentation. The `fmax` parameter can be auto-set. ```python import torch from hear21passt.models.preprocess import AugmentMelSTFT mel = AugmentMelSTFT( n_mels=128, sr=32000, win_length=800, hopsize=320, # default → ~998 frames for 10-s clip n_fft=1024, freqm=48, # max frequency mask width (bins) timem=192, # max time mask width (frames) fmin=0.0, fmax=None, # auto-set to sr/2 − fmax_aug_range/2 fmin_aug_range=10, fmax_aug_range=2000, ) mel.eval() # disable augmentation wave = torch.randn(2, 32000 * 10) # batch of 2 clips spec = mel(wave) print(spec.shape) # torch.Size([2, 128, ~998]) — (batch, mel_bins, time_frames) print(spec.min().item(), spec.max().item()) # roughly normalized around 0 ``` -------------------------------- ### Extract Scene Embeddings with PaSST Source: https://context7.com/kkoutini/passt_hear21/llms.txt Extracts clip-level (scene) embeddings by averaging across overlapping windows for clips longer than the model's window. Runs the model in eval() mode with torch.no_grad(). Output shape is (n_sounds, scene_embedding_size). ```python import torch from hear21passt.base import load_model, get_scene_embeddings model = load_model().cuda() seconds = 15 # longer than the 10 s model window → windowed averaging audio = torch.ones((3, 32000 * seconds)) * 0.5 # 3 sounds × 480 000 samples embed = get_scene_embeddings(audio, model) print(embed.shape) # torch.Size([3, 1295]) print(embed.dtype) # torch.float32 ``` -------------------------------- ### get_scene_embeddings Source: https://context7.com/kkoutini/passt_hear21/llms.txt Extracts clip-level (scene) embeddings by averaging across overlapping windows for clips longer than the model's window. Runs the model in eval() mode with torch.no_grad(). ```APIDOC ## get_scene_embeddings ### Description Returns a single embedding vector per audio clip by averaging across overlapping 10-second windows for clips longer than `max_model_window` (default 10 s). Runs the model in `eval()` mode with `torch.no_grad()`. Output shape is `(n_sounds, scene_embedding_size)`. ### Method `get_scene_embeddings(audio: torch.Tensor, model: PasstBasicWrapper) -> torch.Tensor` ### Parameters #### Path Parameters - **audio** (torch.Tensor) - Required - Input audio tensor. Shape: `(n_sounds, n_samples)`. - **model** (PasstBasicWrapper) - Required - A loaded PaSST model. ### Request Example ```python import torch from hear21passt.base import load_model, get_scene_embeddings model = load_model().cuda() seconds = 15 # longer than the 10 s model window → windowed averaging audio = torch.ones((3, 32000 * seconds)) * 0.5 # 3 sounds × 480 000 samples embed = get_scene_embeddings(audio, model) print(embed.shape) # torch.Size([3, 1295]) print(embed.dtype) # torch.float32 ``` ### Response #### Success Response (torch.Tensor) - Returns a tensor of scene embeddings. Shape: `(n_sounds, scene_embedding_size)`. ``` -------------------------------- ### get_timestamp_embeddings Source: https://context7.com/kkoutini/passt_hear21/llms.txt Extracts frame-level (timestamp) embeddings by sliding a window across the waveform. Returns embeddings and their corresponding center timestamps. ```APIDOC ## get_timestamp_embeddings ### Description Slides a short window (default 160 ms, hop 50 ms) across the waveform and returns an embedding for each frame together with its center timestamp in milliseconds. Output is a tuple `(embeddings, timestamps)` with shapes `(n_sounds, n_timestamps, embedding_size)` and `(n_sounds, n_timestamps)`. ### Method `get_timestamp_embeddings(audio: torch.Tensor, model: PasstBasicWrapper) -> tuple[torch.Tensor, torch.Tensor]` ### Parameters #### Path Parameters - **audio** (torch.Tensor) - Required - Input audio tensor. Shape: `(n_sounds, n_samples)`. - **model** (PasstBasicWrapper) - Required - A loaded PaSST model. ### Request Example ```python import torch from hear21passt.base import load_model, get_timestamp_embeddings model = load_model().cuda() audio = torch.ones((2, 32000 * 10)) * 0.5 # 2 sounds, 10 seconds each embeddings, timestamps = get_timestamp_embeddings(audio, model) print(embeddings.shape) # torch.Size([2, n_timestamps, 1295]) print(timestamps.shape) # torch.Size([2, n_timestamps]) print(timestamps[0, :5]) # center timestamps in ms, e.g. [0, 50, 100, 150, 200] ``` ### Response #### Success Response (tuple[torch.Tensor, torch.Tensor]) - Returns a tuple containing: - `embeddings` (torch.Tensor): Frame-level embeddings. Shape: `(n_sounds, n_timestamps, embedding_size)`. - `timestamps` (torch.Tensor): Center timestamps in milliseconds. Shape: `(n_sounds, n_timestamps)`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.