babysor/MockingBird · error · Exception

Model was not loaded. Call load_model() before inference.

Error message

Model was not loaded. Call load_model() before inference.

What it means

Raised by embed_frames_batch when the module-level _model is None, i.e. inference was attempted before encoder.load_model() initialized the model/device. The encoder uses lazy global state, so any embedding call (embed_utterance, toolbox, VC pipelines) fails until load_model is invoked once.

Source

Thrown at models/encoder/inference.py:60

    if device is None:
        _device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    _device = device
    _model.to(device)

def is_loaded():
    return _model is not None


def embed_frames_batch(frames_batch):
    """
    Computes embeddings for a batch of mel spectrogram.
    
    :param frames_batch: a batch mel of spectrogram as a numpy array of float32 of shape 
    (batch_size, n_frames, n_channels)
    :return: the embeddings as a numpy array of float32 of shape (batch_size, model_embedding_size)
    """
    if _model is None:
        raise Exception("Model was not loaded. Call load_model() before inference.")
    
    frames = torch.from_numpy(frames_batch).to(_device)
    embed = _model.forward(frames).detach().cpu().numpy()
    return embed


def compute_partial_slices(n_samples, partial_utterance_n_frames=partials_n_frames,
                           min_pad_coverage=0.75, overlap=0.5, rate=None):
    """
    Computes where to split an utterance waveform and its corresponding mel spectrogram to obtain 
    partial utterances of <partial_utterance_n_frames> each. Both the waveform and the mel 
    spectrogram slices are returned, so as to make each partial utterance waveform correspond to 
    its spectrogram. This function assumes that the mel spectrogram parameters used are those 
    defined in params_data.py.
    
    The returned ranges may be indexing further than the length of the waveform. It is 
    recommended that you pad the waveform with zeros up to wave_slices[-1].stop.
    

View on GitHub (pinned to 28dc5e14f1)

Solutions

  1. Call encoder.load_model(path_to_encoder.pt) once at startup before any embed_* call
  2. Ensure the weights path is valid and load_model didn't raise (check logs) before inferring
  3. Add an explicit init check/guard in your wrapper that fails fast with a clear message

Example fix

# before
embeds = encoder.embed_utterance(wav)  # _model is None
# after
encoder.load_model(Path('encoder/saved_models/encoder.pt'))
embeds = encoder.embed_utterance(wav)
Defensive patterns

Strategy: validation

Validate before calling

import encoder

if not encoder.is_loaded():
    encoder.load_model(Path('encoder/saved_models/encoder.pt'))
embeds = encoder.embed_utterance(wav)

Type guard

def ensure_encoder_ready() -> bool:
    import encoder
    return getattr(encoder, '_model', None) is not None

Try / catch

try:
    encoder.embed_frames_batch(frames)
except Exception as e:
    if 'load_model' in str(e):
        encoder.load_model(weights_path)  # lazy init then retry once
        return encoder.embed_frames_batch(frames)
    raise

Prevention

When it happens

Trigger: Calling encoder.embed_frames_batch/embed_utterance (directly or via toolbox/VC code) before encoder.load_model(weights_fpath) in the same process; or after a failed/silent load in a subprocess.

Common situations: Reordering startup code so inference runs before model loading; refactoring the toolbox into a service where load_model was skipped; load_model raising earlier and being swallowed so _model stays None.

Related errors


AI-assisted analysis of babysor/MockingBird@28dc5e14f1 (2026-08-27). Data as JSON: /api/errors/dfe35a77a1198626. Report an issue: GitHub.