ReDimNet

repository·master·Indexed 41 days ago

https://github.com/idrnd/redimnet

A neural network architecture for speaker recognition that uses dimensionality reshaping between 1D and 2D blocks to process audio spectrograms. It supports model scales from b0 to M and provides pretrained models via torch.hub. Requires PyTorch >= 2.0 and processes 16 kHz mono audio to extract speaker embeddings of shape [N, 192].

Tokens
2.9K
Snippets
4
Records
6
Agent score
3%

What's inside ReDimNet

  1. What is ReDimNet and how does it work?

    master

    ReDimNet (Reshape Dimensions Network) is a neural network architecture designed for spectrogram (audio) processing to extract utterance-level speaker representations.

    Core Concept: Dimensionality Reshaping The architecture reshapes dimensionality between 2D feature maps and 1D signal representations. This allows the model to integrate 1D and 2D blocks within a single architecture while maintaining the volume of channel-timestep-frequency outputs. This design ensures efficient aggregation of residual feature maps and allows the model to scale from 1 to 15 million parameters.

  2. Perform speaker embedding inference with ReDimNet

    master

    To extract speaker embeddings, provide a 1-channel 16 kHz mono audio signal to the model. The model expects an input tensor of shape [N, T], where N is the batch size and T is the number of samples.

    Inference Workflow

    1. Audio Requirements: 16,000 Hz sampling rate, mono channel.
    2. Device Setup: Move the model to the target device (cuda or cpu).
    3. Precision: Use torch.float16 (AMP) for GPU inference to improve performance, or torch.float32 for CPU.
    4. Mode: Set the model to .eval() mode and use torch.no_grad().
    5. Output: The model returns an embedding of shape [N, 192].
    import torch
    import torchaudio
    
    # 1. Load audio samples (must be 16kHz mono)
    samples, fs = torchaudio.load("assets/audio.wav")  # shape [1, T]
    assert fs == 16000, f"Audio sampling rate {fs} != 16000"
    assert samples.shape[0] == 1, f"Expected mono audio, but got {samples.shape[0]} channels"
    
    # 2. Load model (e.g., mixed dataset version)
    model = torch.hub.load(
    	"IDRnD/ReDimNet",
    	"ReDimNet",
    	model_name="M",
    	train_type="ft_mix",
    	dataset="vb2+vox2+cnc"
    )
    
    # 3. Select device and setup inference precision
    device_type = "cuda" if torch.cuda.is_available() else "cpu"
    device = torch.device(device_type)
    precision = torch.float16 if device_type == "cuda" else torch.float32
    
    # 4. Setup model evaluation mode
    model = model.to(device)
    model.eval()
    
    # 5. Run inference
    with torch.no_grad(), torch.autocast(device_type=device_type, dtype=precision):
        # Input shape [N, T]
        embedding = model(samples.to(device))
        print(embedding.shape, embedding.dtype)  # Output shape: [N, 192]
  3. Load pretrained ReDimNet models via torch.hub

    master

    You can load pretrained ReDimNet models using torch.hub.load. To successfully load a model, you must specify three parameters:

    1. model_name: The size of the model (e.g., 'M', 'S', 'b0', 'b1', etc.).
    2. dataset: The dataset the model was trained on (e.g., 'vb2+vox2+cnc', 'vb2', or 'vox2').
    3. train_type: The training methodology used:
      • 'ptn': Pretrain-only.
      • 'ft_lm': Large-margin finetuning.
      • 'ft_mix': Finetuning with cutmix+mixup augmentations.
    import torch
    
    model_name='M' # ~b3-b4 size
    train_type='ft_mix'
    dataset='vb2+vox2+cnc'
    
    model = torch.hub.load('IDRnD/ReDimNet', 'ReDimNet', 
                           model_name=model_name, 
                           train_type=train_type, 
                           dataset=dataset)
  4. Load ReDimNet models via torch.hub

    master

    ReDimNet models can be loaded directly using torch.hub.load. You can specify the model size (e.g., b0, b1, b2, b3, b5, b6, or M), the training type, and the dataset used for pretraining.

    Loading options

    • model_name: The model scale (e.g., b2).
    • train_type:
      • ptn: Pretrained without Large-Margin finetuning.
      • ft_lm: Pretrained with Large-Margin finetuning.
      • ft_mix: Pretrained and fine-tuned on a mix of datasets (e.g., vb2+vox2+cnc).
    • dataset: The dataset used (e.g., vox2, vb2+vox2+cnc).
    import torch
    
    # Load pretrained on vox2 model without Large-Margin finetuning
    model = torch.hub.load('IDRnD/ReDimNet', 'ReDimNet', model_name='b2', train_type='ptn', dataset='vox2')
    
    # Load pretrained on vox2 model with Large-Margin finetuning
    model = torch.hub.load('IDRnD/ReDimNet', 'ReDimNet', model_name='b2', train_type='ft_lm', dataset='vox2')
  5. Reference: Pretrained model configurations and metrics

    master

    The following table lists available model configurations (size, dataset, and training type) and their corresponding Equal Error Rate (EER) performance metrics across various datasets.

    | Model name (size)   |  Train dataset  |    Train type   |   Vox1-O EER(%) |   Vox1-E EER(%) |   Vox1-H EER(%) |   SITW EER(%) |   VOICES EER(%) |   CN-Celeb EER(%) |
    |:-------------|:-------------|:-------------|-------------:|-------------:|-------------:|-----------:|-------------:|---------------|
    | M            | vb2+vox2+cnc | ft_mix       |            0.835 |            0.745 |            1.284 |          1.203 |            2.703 |              7.474 |
    | M            | vb2          | ptn          |            1.319 |            1.128 |            2.000 |          1.482 |            4.116 |              9.012 |
    | S            | vb2+vox2+cnc | ft_mix       |            0.936 |            0.874 |            1.510 |          1.310 |            2.774 |              8.043 |
    | S            | vb2          | ptn          |            1.542 |            1.408 |            2.505 |          1.781 |            3.987 |              9.592 |
    | b0           | vox2         | ft_lm        |            1.16 |            1.25 |            2.20 |          - |            - |              - |
    | b0           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |
    | b1           | vox2         | ft_lm        |            0.85 |            0.97 |            1.73 |          - |            - |              - |
    | b1           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |
    | b2           | vox2         | ft_lm        |            0.57 |            0.76 |            1.32 |          - |            - |              - |
    | b2           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |
    | b3           | vox2         | ft_lm        |            0.50 |            0.73 |            1.33 |          - |            - |              - |
    | b3           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |
    | b4           | vox2         | ft_lm        |            0.51 |            0.68 |            1.26 |          - |            - |              - |
    | b4           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |
    | b5           | vox2         | ft_lm        |            0.43 |            0.61 |            1.08 |          - |            - |              - |
    | b5           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |
    | b6           | vox2         | ft_lm        |            0.40 |            0.55 |            1.05 |          - |            - |              - |
    | b6           | vox2         | ptn          |            - |            - |            - |          - |            - |              - |