File size: 1,169 Bytes
884b8f8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # marble/core/base_decoder.py
import torch
from abc import ABCMeta, abstractmethod
from typing import Optional
class BaseEncoder(torch.nn.Module, metaclass=ABCMeta):
"""
Abstract base class for encoders. Subclasses need to implement the forward method to encode raw audio or spectrogram
into a feature representation.
Output shape: [batch, time_steps, feature_dim]
"""
def __init__(self, **kwargs):
super().__init__()
# Optionally initialize layers or parameters based on kwargs
@abstractmethod
def forward(self, input_tensor: torch.Tensor, input_len: Optional[torch.Tensor] = None) -> torch.Tensor:
"""
Forward method to map the input (audio, spectrogram, or mel-spectrogram) to high-dimensional features.
Args:
input_tensor: Tensor of shape [batch, time] for audio, or [batch, time_steps, feature_dim] for spectrograms
input_len: Optional tensor of sequence lengths for each input in the batch.
Returns:
Tensor of shape [batch, time_steps, feature_dim]
"""
raise NotImplementedError("Subclasses must implement this method")
|