'How to restore and use trained tacotron2 model

I am new in text-to-speech field. I tried to train Tacotron2 using this tutorial and then I stored checkpoints and nemo file. Now I want to restore model and use it to generate mel spectrograms but I don't know how can I do that.

I found this pytorch code that use pretrained models, then I tried to change Tacotron part of this code to load from my trained model:

from nemo.collections.tts.models import Tacotron2Model
import torch

check_point_path = '/content/drive/My Drive/***/checkpoints/'
tacotron2 = Tacotron2Model.restore_from(check_point_path + 'Tacotron2.nemo')
tacotron2 = tacotron2.to('cuda')
tacotron2.eval()

waveglow = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_waveglow', model_math='fp16')
waveglow = waveglow.remove_weightnorm(waveglow)
waveglow = waveglow.to('cuda')
waveglow.eval()

text = "some words"
utils = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_tts_utils')
sequences, lengths = utils.prepare_input_sequence([text])

with torch.no_grad():
    mel, _, _ = tacotron2.infer(sequences, lengths)
    audio = waveglow.infer(mel)
audio_numpy = audio[0].data.cpu().numpy()
rate = 22050

from IPython.display import Audio
Audio(audio_numpy, rate=rate)

But I get this error:

AttributeError                            Traceback (most recent call last)
<ipython-input-6-32fe16cfb933> in <module>()
     15 with torch.no_grad():
---> 16     mel, _, _ = tacotron2.infer(sequences, lengths)
     17     audio = waveglow.infer(mel)
     18 audio_numpy = audio[0].data.cpu().numpy()

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in __getattr__(self, name)
   1129                 return modules[name]
   1130         raise AttributeError("'{}' object has no attribute '{}'".format(
-> 1131             type(self).__name__, name))
   1132 
   1133     def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:

AttributeError: 'Tacotron2Model' object has no attribute 'infer'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source