axinc-ai / ailia-models

The collection of pre-trained, state-of-the-art AI models for ailia SDK
1.97k stars 315 forks source link

ADD Demucus #866

Open kyakuno opened 2 years ago

kyakuno commented 2 years ago

https://github.com/facebookresearch/demucs

yuki399 commented 2 years ago

opset 17 からサポートされているstftオペレータ利用しているため ailia sdk,pytorch のエクスポート共に非対応

kyakuno commented 2 years ago

@yuki399 opset17を使用してエクスポート頂いても問題ありません。ailia SDK側で対応します。

ooe1123 commented 8 months ago

python -m demucs.separate -o demucs_separated -n htdemucs_ft --mp3 --mp3-bitrate=320 mixture.mp3

ooe1123 commented 8 months ago

nightlyバージョンにてstftのonnxエクスポートも一部は対応されているが、 return_complex=Trueの場合のエクスポートにはまだ対応されていないもよう。

〇 demucs/demucs/apply.py

def apply_model(...):
    ...
    if shifts:
        ...
    elif split:
        ...
    else:
        with th.no_grad():
            out = model(padded_mix)

def apply_model(...):
    ...
    if shifts:
        ...
    elif split:
        ...
    else:
        with th.no_grad():
            import torch
            from torch.autograd import Variable
            x = Variable(padded_mix)
            torch.onnx.export(
                model, x, 'xxx.onnx',
                input_names=["padded_mix"],
                output_names=["out"],
                verbose=False, opset_version=17
            )
torch.onnx.errors.SymbolicValueError: STFT does not currently support complex types  [Caused by the value '636 defined in (%636 : Float(*, *, strides=[351232, 1], requires_grad=0, device=cuda:0) = onnx::Reshape[allowzero=0](%626, %635), scope: demucs.htdemucs.HTDemucs:: # /home/ooe/env_nightly/lib/python3.8/site-packages/torch/functional.py:649:0
ooe1123 commented 8 months ago

torch.onnx.dynamo_exportを使う方法もいまのところダメだった。

from user code:
   File "/home/ooe/demucs/demucs/htdemucs.py", line 534, in forward
    training_length = int(self.segment * self.samplerate)
  File "/usr/lib/python3.8/fractions.py", line 384, in forward
    return monomorphic_operator(a, b)
  File "/usr/lib/python3.8/fractions.py", line 427, in _mul
    return Fraction(a.numerator * b.numerator, a.denominator * b.denominator)

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
....
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues