NVIDIA / tacotron2

Tacotron 2 - PyTorch implementation with faster-than-realtime inference
BSD 3-Clause "New" or "Revised" License
5.03k stars 1.37k forks source link

i want transfer tacotron2 model to onnx but there is an error ㅠ #190

Closed wojung closed 5 years ago

wojung commented 5 years ago

i want to transfer pre-trained tacotron2 model to onnx

first load model

    hparams = create_hparams()
    hparams.sampling_rate = 22050
    checkpoint_path = "tacotron2_statedict.pt"
    model = load_model(hparams)
    model.load_state_dict(torch.load(checkpoint_path)['state_dict'])
    _ = model.eval()

and i set input like this

    text_inputs = torch.randn(64, 163, device='cuda')
    text_legths = torch.randn(64, device='cuda')
    mels = torch.randn(64, 80, 851, device='cuda')
    max_len = 163
    output_lengths = torch.randn(64, device='cuda')

    dummy_input = (text_inputs, text_legths, mels, max_len, output_lengths)

and try to transfer model to onnx

    dummy_input = (text_inputs, text_legths, mels, max_len, output_lengths)

but there is an error

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

Traceback (most recent call last):
  File "inference.py", line 49, in <module>
    torch.onnx.export(model, dummy_input, "tacotron.onnx", verbose=True )
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/onnx/__init__.py", line 27, in export
    return utils.export(*args, **kwargs)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/onnx/utils.py", line 104, in export
    operator_export_type=operator_export_type)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/onnx/utils.py", line 281, in _export
    example_outputs, propagate)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/onnx/utils.py", line 224, in _model_to_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args, training)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/onnx/utils.py", line 192, in _trace_and_get_graph_from_model
    trace, torch_out = torch.jit.get_trace_graph(model, args, _force_outplace=True)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/jit/__init__.py", line 197, in get_trace_graph
    return LegacyTracedModule(f, _force_outplace)(*args, **kwargs)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/msl/.virtualenvs/venv_waveglow/lib/python3.5/site-packages/torch/jit/__init__.py", line 243, in forward
    in_vars, in_desc = _flatten(args)
RuntimeError: Only tuples, lists and Variables supported as JIT inputs, but got int

Is the input value wrong??? ㅠㅠ

rafaelvalle commented 5 years ago
RuntimeError: Only tuples, lists and Variables supported as JIT inputs, but got int

But max_len is int:

    max_len = 163

Try wrapping it into a list and changing the remainder of the code that interacts with max_len

wojung commented 5 years ago

i think tacotron seems to want an int as an input. i will try thank you so much

RatulGhosh commented 5 years ago

@wojung are you able to successfully transfer the model to onnx?

wojung commented 5 years ago

nope. i failed to transfer to onnx sorry

ajaysg-zz commented 5 years ago

waveglow_path = './waveglow_256channels.pt' waveglow = torch.load(waveglow_path)['model']

mel_extra=torch.tensor(np.full((1,80,222),-10.0)).float() dummy_input=torch.autograd.Variable(mel_extra).cuda().float()

audio = torch.tensor(np.full((1,222), -0.5)).float() audio_input = torch.autograd.Variable(audio).cuda().float() torch.onnx.export(waveglow, ((dummy_input, audio_input),), "./waveglow.onnx")

It can start to run export, but since logdet operator is not supported, export failed.

/home/user/anaconda3/envs/pytts/lib/python3.6/site-packages/torch/onnx/utils.py:501: UserWarning: ONNX export failed on ATen operator logdet because torch.onnx.symbolic.logdet does not exist ...... RuntimeError: ONNX export failed: Couldn't export operator aten::logdet

@rafaelvalle same problem with waveglow model beacuse lodget operator is not supported. any idea

omkar5199 commented 4 years ago

@wojung max_len = torch.tensor(163) I used this and the error you mentioned was solved. I got another error


TypeError Traceback (most recent call last)

in () 23 output_lengths = torch.randn(64, device='cpu') 24 dummy_input = (text_inputs, text_legths, mels, max_len, output_lengths) ---> 25 torch.onnx.export(model, dummy_input, "tacotron.onnx", verbose=True) 10 frames /usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in _slow_forward(self, *input, **kwargs) 514 recording_scopes = False 515 try: --> 516 result = self.forward(*input, **kwargs) 517 finally: 518 if recording_scopes: TypeError: forward() takes 2 positional arguments but 6 were given
lightwithshadow commented 3 years ago

finally solved? @wojung