前提・実現したいこと
環境:windows10
言語:Python3.6.8
ターミナル:Git Bash
ソフトウェア:become-yukarin
A.3 第1段を使った音声変換
上記のリンク先の記事を参考に作業を行っており、以下のコマンドを実行しました。
python become-yukarin/scripts/voice_conversion_test.py 1st_yukari_model_by \ -iwd dat/1st_models_by/yukari/voice_pair/own \ -md dat/1st_models_by/yukari \ -it 120000
このコマンドで音声変換ができるはずなのですが、以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
yff30@DESKTOP-DPOI2G3 MINGW64 /d/ユーザー名hdd/deep_yukarin $ python become-yukarin/scripts/voice_conversion_test.py 1st_yukari_model_by \ > -iwd dat/1st_models_by/yukari/voice_pair/own \ > -md dat/1st_models_by/yukari \ > -it 120000 Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main exitcode = _main(fd) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main prepare(preparation_data) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path run_name="__mp_main__") File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "D:\hidekazuhdd\deep_yukarin\become-yukarin\scripts\voice_conversion_test.py", line 73, in <module> pool = multiprocessing.Pool() File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 119, in Pool context=self.get_context()) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py", line 174, in __init__ self._repopulate_pool() File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\pool.py", line 239, in _repopulate_pool w.start() File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\process.py", line 105, in start self._popen = self._Popen(self) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__ prep_data = spawn.get_preparation_data(process_obj._name) File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 143, in get_preparation_data _check_not_importing_main() File "C:\Users\yff30\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main is not going to be frozen to produce an executable.''') 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. dat\1st_models_by\yukari\1st_yukari_model_by\predictor_120000.npz
エラーメッセージと想定される解決法
このエラーメッセージについて調べを進めていったところ、以下のリンクの記事が見つかりました。
multiprocessを使ったコードをpython setup.py testする
WindowsでCUDA+PyTorchのサンプル実行するまでのメモ
Python で並列処理(初めての人向け)
これらの記事の内容から、おそらく該当のソースコードに
def main() if __name__ == '__main__': main()
これらを記述する必要があると考えました。
該当のソースコード(voice_conversion_test.py)
import argparse import glob import multiprocessing import re from functools import partial from pathlib import Path import librosa import numpy from become_yukarin import AcousticConverter from become_yukarin.config.config import create_from_json as create_config parser = argparse.ArgumentParser() parser.add_argument('model_names', nargs='+') parser.add_argument('-md', '--model_directory', type=Path, default=Path('/mnt/dwango/hiroshiba/become-yukarin/')) parser.add_argument('-iwd', '--input_wave_directory', type=Path, default=Path('/mnt/dwango/hiroshiba/become-yukarin/dataset/hiho-wave/hiho-pause-atr503-subset/')) parser.add_argument('-it', '--iteration', type=int) parser.add_argument('-g', '--gpu', type=int) args = parser.parse_args() model_directory = args.model_directory # type: Path input_wave_directory = args.input_wave_directory # type: Path it = args.iteration gpu = args.gpu paths_test = list(Path('./test_data/').glob('*.wav')) def extract_number(f): s = re.findall("\d+", str(f)) return int(s[-1]) if s else -1 def process(p: Path, acoustic_converter: AcousticConverter): try: if p.suffix in ['.npy', '.npz']: fn = glob.glob(str(input_wave_directory / p.stem) + '.*')[0] p = Path(fn) wave = acoustic_converter(p) librosa.output.write_wav(str(output / p.stem) + '.wav', wave.wave, wave.sampling_rate, norm=True) except: import traceback print('error!', str(p)) print(traceback.format_exc()) for model_name in args.model_names: base_model = model_directory / model_name config = create_config(base_model / 'config.json') input_paths = list(sorted([Path(p) for p in glob.glob(str(config.dataset.input_glob))])) numpy.random.RandomState(config.dataset.seed).shuffle(input_paths) path_train = input_paths[0] path_test = input_paths[-1] if it is not None: model_path = base_model / 'predictor_{}.npz'.format(it) else: model_paths = base_model.glob('predictor_*.npz') model_path = list(sorted(model_paths, key=extract_number))[-1] print(model_path) acoustic_converter = AcousticConverter(config, model_path, gpu=gpu) output = Path('./output').absolute() / base_model.name output.mkdir(exist_ok=True) paths = [path_train, path_test] + paths_test process_partial = partial(process, acoustic_converter=acoustic_converter) if gpu is None: pool = multiprocessing.Pool() pool.map(process_partial, paths) else: list(map(process_partial, paths))
質問したいこと
エラーの内容と考えられる解決法までは調べられたのですが、
果たして上記の該当のソースコードのどの部分にどのように記述すれば良いのか分からず困っています。
if name=='main'でどのように囲めばよいのかご教授いただきたく思います。