Implementation:Facebookresearch Audiocraft WMLoss
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Audio_Watermarking, Loss_Functions |
| Last Updated | 2026-02-14 01:00 GMT |
Overview
Concrete tool for computing watermark detection and multi-bit message decoding losses for AudioSeal training.
Description
This module provides WMDetectionLoss for binary watermark presence/absence classification using NLL loss on detector outputs, and WMMbLoss for multi-bit message decoding using either BCE or MSE loss. Both losses support masked regions for localization-aware training.
Usage
Import these losses when training AudioSeal watermarking models. They are used by WatermarkSolver during the training loop.
Code Reference
Source Location
- Repository: Facebookresearch_Audiocraft
- File: audiocraft/losses/wmloss.py
- Lines: 1-104
Signature
class WMDetectionLoss(nn.Module):
def __init__(self, p_weight: float = 1.0, n_weight: float = 1.0):
"""Binary watermark detection loss."""
def forward(self, positive, negative, mask, message) -> torch.Tensor: ...
class WMMbLoss(nn.Module):
def __init__(self, temperature: float, loss_type: Literal["bce", "mse"] = "bce"):
"""Multi-bit message decoding loss."""
def forward(self, positive, negative, mask, message) -> torch.Tensor: ...
Import
from audiocraft.losses.wmloss import WMDetectionLoss, WMMbLoss
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| positive | torch.Tensor | Yes | Detector output for watermarked audio [B, 2+nbits, T] |
| negative | torch.Tensor | Yes | Detector output for clean audio [B, 2+nbits, T] |
| mask | torch.Tensor | Yes | Watermark region mask [B, 1, T] |
| message | torch.Tensor | No | Original message bits [B, nbits] (for WMMbLoss) |
Outputs
| Name | Type | Description |
|---|---|---|
| loss | torch.Tensor | Scalar loss value |
Usage Examples
from audiocraft.losses.wmloss import WMDetectionLoss, WMMbLoss
det_loss = WMDetectionLoss(p_weight=1.0, n_weight=1.0)
mb_loss = WMMbLoss(temperature=1.0, loss_type="bce")
loss = det_loss(positive, negative, mask, None) + mb_loss(positive, negative, mask, message)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment