deezer / spleeter

Deezer source separation library including pretrained models.
https://research.deezer.com/projects/spleeter.html
MIT License
25.62k stars 2.81k forks source link

[Bug]Python code for spleeter basics does not work #825

Open gitinmathew opened 1 year ago

gitinmathew commented 1 year ago

Description

Command line works but python code does NOT

Command line PS C:\Users...\Desktop> spleeter separate -p spleeter:2stems -o output .\ABCD.mp3 INFO:spleeter:File output\ABCD/accompaniment.wav written succesfully INFO:spleeter:File output\ABCD/vocals.wav written succesfully

Python code from spleeter.separator import Separator from spleeter.audio.adapter import AudioAdapter

separator = Separator('spleeter:2stems') audio_loader = AudioAdapter.default() samplerate = 44100 waveform, = audio_loader.load('C:/Users/.../Desktop/.../ABCD.mp3', sample_rate=sample_rate)

prediction1 = separator.separate(waveform)

Step to reproduce

Python code from spleeter.separator import Separator from spleeter.audio.adapter import AudioAdapter

separator = Separator('spleeter:2stems') audio_loader = AudioAdapter.default() samplerate = 44100 waveform, = audio_loader.load('C:/Users/.../Desktop/.../ABCD.mp3', sample_rate=sample_rate)

prediction1 = separator.separate(waveform)

  1. Installed using pip
  2. Run as ...
  3. Got ... error

Output

File "C:\Users...\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main raise RuntimeError(''' RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

Environment

Windows 11 Pro

OS Windows
Installation type pip
RAM available XGo
Hardware spec GPU / CPU / etc ...

Additional context

vadd98 commented 1 year ago

Hi, did you managed to solve this issue? I'm getting the same problem on Windows 11

119010291 commented 1 year ago

I'm getting the same problem on macOS

shuZro commented 1 year ago

Same issue on win 10

perspektyvus commented 1 year ago

This issue arises because of the way multiprocessing works for Python on Windows. You have to account for it manually, so here's a simple example with a separator:

from spleeter.separator import Separator
from multiprocessing import freeze_support

def main():
    # Your logic here, encapsulated in a function
    separator = Separator('spleeter:4stems')
    separator.separate_to_file('song.wav', 'audio/output')

if __name__ == '__main__':
    # Running your logic
    freeze_support()
    main()
InstaMinerAi commented 4 months ago

This issue arises because of the way multiprocessing works for Python on Windows. You have to account for it manually, so here's a simple example with a separator:

from spleeter.separator import Separator
from multiprocessing import freeze_support

def main():
    # Your logic here, encapsulated in a function
    separator = Separator('spleeter:4stems')
    separator.separate_to_file('song.wav', 'audio/output')

if __name__ == '__main__':
    # Running your logic
    freeze_support()
    main()

Thanks buddy that really fixed the problem!

Bill-XU commented 3 months ago

Setting parameter "multiprocess" to False disables multiprocessing ability of separator separator = Separator('spleeter:2stems', multiprocess = False)