my_module = GetSpeechEmbedding()
sm = torch.jit.script(my_module)
sm.save("annotated_get_speech_embedding.pt")
But when trying to serialize the module, I get this error:
"torch.jit.frontend.UnsupportedNodeError: DictComp aren't supported"
(venv373) (base) marco@pc01:~/PyTorchMatters/Resemblyzer$ python3
./getSpeechEmbedding.py
Traceback (most recent call last):
File "./getSpeechEmbedding.py", line 114, in <module>
sm = torch.jit.script(my_module)
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1255, in
script
return torch.jit._recursive.recursive_script(obj)
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 534, in
recursive_script
return create_script_module(nn_module, infer_methods_to_compile(nn_module))
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 493, in
infer_methods_to_compile
stubs.append(make_stub_from_method(nn_module, method))
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 40, in
make_stub_from_method
return make_stub(func)
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 33, in
make_stub
ast = torch.jit.get_jit_def(func, self_name="RecursiveScriptModule")
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 171, in
get_jit_def
return build_def(ctx, py_ast.body[0], type_line, self_name)
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 212, in
build_def
build_stmts(ctx, body))
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 127, in
build_stmts
stmts = [build_stmt(ctx, s) for s in stmts]
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 127, in
<listcomp>
stmts = [build_stmt(ctx, s) for s in stmts]
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 187, in
__call__
return method(ctx, node)
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 289, in
build_Assign
rhs = build_expr(ctx, stmt.value)
File "/home/marco/anaconda3/lib/python3.7/site-packages/torch/jit/frontend.py", line 186, in
__call__
raise UnsupportedNodeError(ctx, node)
torch.jit.frontend.UnsupportedNodeError: DictComp aren't supported:
File "./getSpeechEmbedding.py", line 46
# It normalizes the volume, trims long silences and resamples the wav to the correct
sampling rate.
speaker_wavs = {speaker: list(map(preprocess_wav, wav_fpaths)) for speaker, wav_fpaths
in
~ <--- HERE
groupby(tqdm(wav_fpaths, "Preprocessing wavs", len(wav_fpaths), unit="wavs"),
lambda wav_fpath: wav_fpath.parent.stem)}
I read here: https://pytorch.org/tutorials/advanced/cpp_export.html
that "If you need to exclude some methods in your nn.Module because they use Python features that TorchScript doesn’t support yet, you could annotate those with @torch.jit.ignore"
But I guess that excluding the dictionary comprehension from the serialization, will interfere with the method's functionality.
What would you suggest me to do?
I know it's not strictly related to Resemblyzer library, but I do hope that may be you or others can give me an help.
My objective is to use the following class which simply uses your excellent work:
With python it works fine:
Following the indications found here: https://pytorch.org/tutorials/advanced/cpp_export.html
I added to getSpeechEmbedding.py these lines:
But when trying to serialize the module, I get this error: "torch.jit.frontend.UnsupportedNodeError: DictComp aren't supported"
I read here: https://pytorch.org/tutorials/advanced/cpp_export.html that "If you need to exclude some methods in your nn.Module because they use Python features that TorchScript doesn’t support yet, you could annotate those with @torch.jit.ignore" But I guess that excluding the dictionary comprehension from the serialization, will interfere with the method's functionality. What would you suggest me to do?