docstr: :param device: either a torch device or the name of a torch device (e.g. "cpu", "cuda").
  If None, defaults to cuda if it is available on your machine, otherwise the model will
  run on cpu. Outputs are always returned on the cpu, as numpy arrays.
docstr_tok: [":","param","device",":","either","a","torch","device","or","the","name","of","a","torch","device","(","e.g",".","``","cpu","''",",","``","cuda","''",")",".","If","None",",","defaults","to","cuda","if","it","is","available","on","your","machine",",","otherwise","the","model","will","run","on","cpu",".","Outputs","are","always","returned","on","the","cpu",",","as","numpy","arrays","."]
code: def __init__(
      self,
      weights_fpath,
      device: Union[str, torch.device] = None,
      verbose=True,
  ):
      """
      :param device: either a torch device or the name of a torch device (e.g. "cpu", "cuda").
      If None, defaults to cuda if it is available on your machine, otherwise the model will
      run on cpu. Outputs are always returned on the cpu, as numpy arrays.
      """
      super().__init__()
  
      # Define the network
      self.lstm = nn.LSTM(
          mel_n_channels,
          model_hidden_size,
          model_num_layers,
          batch_first=True,
      )
      self.linear = nn.Linear(model_hidden_size, model_embedding_size)
      self.relu = nn.ReLU()
  
      # Get the target device
      if device is None:
          device = torch.device(
              "cuda" if torch.cuda.is_available() else "cpu"
          )
      elif isinstance(device, str):
          device = torch.device(device)
      self.device = device
  
      # Load the pretrained model'speaker weights
      # weights_fpath = Path(__file__).resolve().parent.joinpath("pretrained.pt")
      # if not weights_fpath.exists():
      #     raise Exception("Couldn't find the voice encoder pretrained model at %s." %
      #                     weights_fpath)
  
      start = timer()
      checkpoint = load_fsspec(weights_fpath, map_location="cpu")
  
      self.load_state_dict(checkpoint["model_state"], strict=False)
      self.to(device)
  
      if verbose:
          print(
              "Loaded the voice encoder model on %s in %.2f seconds."
              % (device.type, timer() - start)
          )
  
file_path: TTS/TTS/vc/modules/freevc/speaker_encoder/speaker_encoder.py
imports: from pathlib import Path
  from time import perf_counter
  from typing import List, Union
  import numpy
  import torch
  from torch import nn
  from TTS.utils.io import load_fsspec
  from TTS.vc.modules.freevc.speaker_encoder import audio
  from TTS.vc.modules.freevc.speaker_encoder.hparams import *
label_desc: Use image node_id 1 to create a new SpeakerEncoder object from inherited base classes: nn with example: obj = SpeakerEncoder(weights_fpath, device, verbose)