This commit is contained in:
wataru 2022-12-09 12:52:27 +09:00
parent 3f2462933a
commit 31507fae62
18 changed files with 165 additions and 100 deletions

View File

@ -6,8 +6,8 @@ from distutils.util import strtobool
import numpy as np import numpy as np
from scipy.io.wavfile import write, read from scipy.io.wavfile import write, read
sys.path.append("/MMVC_Trainer") sys.path.append("MMVC_Trainer")
sys.path.append("/MMVC_Trainer/text") sys.path.append("MMVC_Trainer/text")
from fastapi.routing import APIRoute from fastapi.routing import APIRoute
from fastapi import HTTPException, Request, Response, FastAPI, UploadFile, File, Form from fastapi import HTTPException, Request, Response, FastAPI, UploadFile, File, Form
@ -244,7 +244,7 @@ if __name__ == thisFilename or args.colab == True:
# ########## # ##########
UPLOAD_DIR = "upload_dir" UPLOAD_DIR = "upload_dir"
os.makedirs(UPLOAD_DIR, exist_ok=True) os.makedirs(UPLOAD_DIR, exist_ok=True)
MODEL_DIR = "/MMVC_Trainer/logs" MODEL_DIR = "MMVC_Trainer/logs"
os.makedirs(MODEL_DIR, exist_ok=True) os.makedirs(MODEL_DIR, exist_ok=True)
@app_fastapi.post("/upload_file") @app_fastapi.post("/upload_file")
@ -290,7 +290,7 @@ if __name__ == thisFilename or args.colab == True:
): ):
zipFilePath = concat_file_chunks( zipFilePath = concat_file_chunks(
UPLOAD_DIR, zipFilename, zipFileChunkNum, UPLOAD_DIR) UPLOAD_DIR, zipFilename, zipFileChunkNum, UPLOAD_DIR)
shutil.unpack_archive(zipFilePath, "/MMVC_Trainer/dataset/textful/") shutil.unpack_archive(zipFilePath, "MMVC_Trainer/dataset/textful/")
return {"Zip file unpacked": f"{zipFilePath}"} return {"Zip file unpacked": f"{zipFilePath}"}
############ ############

1
demo/MMVC_Trainer Submodule

@ -0,0 +1 @@
Subproject commit 39723b3243e0265b8802e020e4d4d90a4b8b65ee

35
demo/exec.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
set -eu
MODE=$1
PARAMS=${@:2:($#-1)}
echo "------"
echo "$@"
echo "TYPE: $MODE"
echo "PARAMS: $PARAMS"
# echo "VERBOSE: $VERBOSE"
echo "------"
cd /voice-changer-internal/voice-change-service
# 起動
if [ "${MODE}" = "MMVC" ] ; then
if [[ -e /resources/setting.json ]]; then
echo "指定された設定(setting.json)を使用します。"
cp /resources/setting.json ../frontend/dist/assets/setting.json
fi
find /resources/ -type f -name "config.json" | xargs -I{} sh -c 'echo "config.jsonをコピーします。" && cp {} ./'
find /resources/ -type f -name "*.pth" | xargs -I{} sh -c 'echo "`basename {}`をコピーします。" && cp {} ./'
echo "MMVCを起動します"
python3 MMVCServerSIO.py -t MMVC $PARAMS #2>stderr.txt
elif [ "${MODE}" = "TRAIN" ] ; then
python3 -m tensorboard.main --logdir /MMVC_Trainer/logs --port 6006 --host 0.0.0.0 &
python3 MMVCServerSIO.py -t TRAIN $PARAMS
fi

View File

@ -3,11 +3,11 @@ from fastapi.responses import FileResponse
import os import os
def mod_get_model(modelFile:str): def mod_get_model(modelFile:str):
modelPath = os.path.join("/MMVC_Trainer/logs", modelFile) modelPath = os.path.join("MMVC_Trainer/logs", modelFile)
return FileResponse(path=modelPath) return FileResponse(path=modelPath)
def mod_delete_model(modelFile:str): def mod_delete_model(modelFile:str):
modelPath = os.path.join("/MMVC_Trainer/logs", modelFile) modelPath = os.path.join("MMVC_Trainer/logs", modelFile)
os.unlink(modelPath) os.unlink(modelPath)
return {"Model deleted": f"{modelFile}"} return {"Model deleted": f"{modelFile}"}

View File

@ -5,8 +5,8 @@ from trainer_mods.files import get_file_list
import os import os
def mod_get_models(): def mod_get_models():
gModels = get_file_list(f'/MMVC_Trainer/logs/G*.pth') gModels = get_file_list(f'MMVC_Trainer/logs/G*.pth')
dModels = get_file_list(f'/MMVC_Trainer/logs/D*.pth') dModels = get_file_list(f'MMVC_Trainer/logs/D*.pth')
models = [] models = []
models.extend(gModels) models.extend(gModels)
models.extend(dModels) models.extend(dModels)

View File

@ -2,7 +2,7 @@ from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
import os import os
MULTI_SPEAKER_SETTING_PATH = "/MMVC_Trainer/dataset/multi_speaker_correspondence.txt" MULTI_SPEAKER_SETTING_PATH = "MMVC_Trainer/dataset/multi_speaker_correspondence.txt"
def mod_get_multi_speaker_setting(): def mod_get_multi_speaker_setting():
data = {} data = {}
if os.path.isfile(MULTI_SPEAKER_SETTING_PATH) == False: if os.path.isfile(MULTI_SPEAKER_SETTING_PATH) == False:

View File

@ -2,7 +2,7 @@ import shutil
from mods.Trainer_MultiSpeakerSetting import MULTI_SPEAKER_SETTING_PATH from mods.Trainer_MultiSpeakerSetting import MULTI_SPEAKER_SETTING_PATH
def mod_delete_speaker(speaker:str): def mod_delete_speaker(speaker:str):
shutil.rmtree(f"/MMVC_Trainer/dataset/textful/{speaker}") shutil.rmtree(f"MMVC_Trainer/dataset/textful/{speaker}")
with open(MULTI_SPEAKER_SETTING_PATH, "r") as f: with open(MULTI_SPEAKER_SETTING_PATH, "r") as f:
setting = f.readlines() setting = f.readlines()

View File

@ -3,9 +3,9 @@ from fastapi.encoders import jsonable_encoder
import os, base64 import os, base64
def mod_get_speaker_voice(speaker:str, voice:str): def mod_get_speaker_voice(speaker:str, voice:str):
wav_file = f'/MMVC_Trainer/dataset/textful/{speaker}/wav/{voice}.wav' wav_file = f'MMVC_Trainer/dataset/textful/{speaker}/wav/{voice}.wav'
text_file = f'/MMVC_Trainer/dataset/textful/{speaker}/text/{voice}.txt' text_file = f'MMVC_Trainer/dataset/textful/{speaker}/text/{voice}.txt'
readable_text_file = f'/MMVC_Trainer/dataset/textful/{speaker}/readable_text/{voice}.txt' readable_text_file = f'MMVC_Trainer/dataset/textful/{speaker}/readable_text/{voice}.txt'
data = {} data = {}
if os.path.exists(wav_file): if os.path.exists(wav_file):

View File

@ -4,11 +4,11 @@ from trainer_mods.files import get_file_list
import os import os
def mod_get_speaker_voices(speaker:str): def mod_get_speaker_voices(speaker:str):
voices = get_file_list(f'/MMVC_Trainer/dataset/textful/{speaker}/wav/*.wav') voices = get_file_list(f'MMVC_Trainer/dataset/textful/{speaker}/wav/*.wav')
texts = get_file_list(f'/MMVC_Trainer/dataset/textful/{speaker}/text/*.txt') texts = get_file_list(f'MMVC_Trainer/dataset/textful/{speaker}/text/*.txt')
readable_texts = get_file_list(f'/MMVC_Trainer/dataset/textful/{speaker}/readable_text/*.txt') readable_texts = get_file_list(f'MMVC_Trainer/dataset/textful/{speaker}/readable_text/*.txt')
items = voices items = voices
items.extend(texts) items.extend(texts)

View File

@ -5,8 +5,8 @@ import os
# CreateはFileUploaderで実装。 # CreateはFileUploaderで実装。
def mod_get_speakers(): def mod_get_speakers():
os.makedirs("/MMVC_Trainer/dataset/textful", exist_ok=True) os.makedirs("MMVC_Trainer/dataset/textful", exist_ok=True)
speakers = get_dir_list("/MMVC_Trainer/dataset/textful/") speakers = get_dir_list("MMVC_Trainer/dataset/textful/")
data = { data = {
"speakers":sorted(speakers) "speakers":sorted(speakers)

View File

@ -3,7 +3,7 @@ from trainer_mods.files import get_file_list
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
LOG_DIR = "/MMVC_Trainer/info" LOG_DIR = "MMVC_Trainer/info"
train_proc = None train_proc = None
SUCCESS = 0 SUCCESS = 0
@ -13,7 +13,7 @@ def sync_exec(cmd:str, log_path:str):
shortCmdStr = cmd[:20] shortCmdStr = cmd[:20]
try: try:
with open(log_path, 'w') as log_file: with open(log_path, 'w') as log_file:
proc = subprocess.run(cmd, shell=True, text=True, stdout=log_file, stderr=log_file, cwd="/MMVC_Trainer") proc = subprocess.run(cmd, shell=True, text=True, stdout=log_file, stderr=log_file, cwd="MMVC_Trainer")
print(f"{shortCmdStr} returncode:{proc.returncode}") print(f"{shortCmdStr} returncode:{proc.returncode}")
if proc.returncode != 0: if proc.returncode != 0:
print(f"{shortCmdStr} exception:") print(f"{shortCmdStr} exception:")
@ -28,7 +28,7 @@ def sync_exec_with_stdout(cmd:str, log_path:str):
try: try:
with open(log_path, 'w') as log_file: with open(log_path, 'w') as log_file:
proc = subprocess.run(cmd, shell=True, text=True, stdout=subprocess.PIPE, proc = subprocess.run(cmd, shell=True, text=True, stdout=subprocess.PIPE,
stderr=log_file, cwd="/MMVC_Trainer") stderr=log_file, cwd="MMVC_Trainer")
print(f"STDOUT{shortCmdStr}",proc.stdout) print(f"STDOUT{shortCmdStr}",proc.stdout)
except Exception as e: except Exception as e:
print(f"{shortCmdStr} exception:", str(e)) print(f"{shortCmdStr} exception:", str(e))
@ -43,13 +43,13 @@ def create_dataset():
return res return res
def set_batch_size(batch:int): def set_batch_size(batch:int):
cmd = "sed -i 's/\"batch_size\": [0-9]*/\"batch_size\": " + str(batch) + "/' /MMVC_Trainer/configs/baseconfig.json" cmd = "sed -i 's/\"batch_size\": [0-9]*/\"batch_size\": " + str(batch) + "/' MMVC_Trainer/configs/baseconfig.json"
log_file = os.path.join(LOG_DIR, "log_set_batch_size.txt") log_file = os.path.join(LOG_DIR, "log_set_batch_size.txt")
res = sync_exec(cmd, log_file) res = sync_exec(cmd, log_file)
return res return res
def set_dummy_device_count(): def set_dummy_device_count():
cmd = 'sed -ie "s/torch.cuda.device_count()/1/" /MMVC_Trainer/train_ms.py' cmd = 'sed -ie "s/torch.cuda.device_count()/1/" MMVC_Trainer/train_ms.py'
log_file = os.path.join(LOG_DIR, "log_set_dummy_device_count.txt") log_file = os.path.join(LOG_DIR, "log_set_dummy_device_count.txt")
res = sync_exec(cmd, log_file) res = sync_exec(cmd, log_file)
return res return res
@ -73,7 +73,7 @@ def exec_training():
with open(log_file, 'w') as log_file: with open(log_file, 'w') as log_file:
cmd = 'python3 train_ms.py -c configs/train_config.json -m ./' cmd = 'python3 train_ms.py -c configs/train_config.json -m ./'
print("exec:",cmd) print("exec:",cmd)
train_proc = subprocess.Popen("exec "+cmd, shell=True, text=True, stdout=log_file, stderr=log_file, cwd="/MMVC_Trainer") train_proc = subprocess.Popen("exec "+cmd, shell=True, text=True, stdout=log_file, stderr=log_file, cwd="MMVC_Trainer")
print("Training stated") print("Training stated")
print(f"returncode:{train_proc.returncode}") print(f"returncode:{train_proc.returncode}")
except Exception as e: except Exception as e:
@ -133,11 +133,11 @@ def mod_post_stop_training():
def mod_get_related_files(): def mod_get_related_files():
files = get_file_list(os.path.join(LOG_DIR,"*")) files = get_file_list(os.path.join(LOG_DIR,"*"))
files.extend([ files.extend([
"/MMVC_Trainer/dataset/multi_speaker_correspondence.txt", "MMVC_Trainer/dataset/multi_speaker_correspondence.txt",
"/MMVC_Trainer/train_ms.py", "MMVC_Trainer/train_ms.py",
]) ])
files.extend( files.extend(
get_file_list("/MMVC_Trainer/configs/*") get_file_list("MMVC_Trainer/configs/*")
) )
res = [] res = []

View File

@ -1,56 +1,18 @@
#!/bin/bash #!/bin/bash
# 参考:https://programwiz.org/2022/03/22/how-to-write-shell-script-for-option-parsing/
set -eu set -eu
# 実行ユーザ作成
USER_ID=${LOCAL_UID:-9001}
GROUP_ID=${LOCAL_GID:-9001}
if [ $# = 0 ]; then echo "exec with [UID : $USER_ID, GID: $GROUP_ID]"
echo " useradd -u $USER_ID -o -m user
usage: groupmod -g $GROUP_ID user
$0 -t <TYPE> <params...>
TYPE: select one of ['TRAIN', 'MMVC']
" >&2
exit 1
fi
# TYPE=$1
# PARAMS=${@:2:($#-1)}
# echo $TYPE
# echo $PARAMS
if [ -e /resources ]; then
echo "/resources の中身をコピーします。"
cp -r /resources/* .
else
echo "/resourcesが存在しません。デフォルトの動作をします。"
fi
## Config 設置
if [[ -e ./setting.json ]]; then
echo "カスタムセッティングを使用"
cp ./setting.json ../frontend/dist/assets/setting.json
fi
echo "起動します" "$@"
python3 MMVCServerSIO.py "$@"
###
# 起動パラメータ
# (1) トレーニングの場合
# python3 MMVCServerSIO.py -t <type> [--https on|off, --httpsKey <key>, --httpsCert <key>, --httpsSelfSigned on|off]
# 環境変数: EX_PORT, EX_TB_PORT, EX_IP (EX_IPはEX_IP="`hostname -I`"で自動取得)
# ※ Colabの場合python3 MMVCServerSIO.py -t Train -p {PORT} --colab True
# (2) VCの場合
# # 起動
# if [ "${TYPE}" = "MMVC" ] ; then
# elif [ "${TYPE}" = "MMVC_VERBOSE" ] ; then
# echo "MMVCを起動します(verbose)"
# python3 MMVCServerSIO.py $PARAMS
# fi
#su user
#echo "parameter: $@"
exec /usr/sbin/gosu user /bin/bash exec.sh "$@"
#/bin/bash

View File

@ -1,4 +1,4 @@
FROM dannadori/voice-changer-internal:20221114_095228 as front FROM dannadori/voice-changer-internal:20221209_112157 as front
FROM debian:bullseye-slim as base FROM debian:bullseye-slim as base
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
@ -48,29 +48,33 @@ RUN apt-get update \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
### Copy local resource # ### Copy local resource
COPY fine_model/G_180000.pth /MMVC_Trainer/fine_model/G_180000.pth # COPY fine_model/G_180000.pth /MMVC_Trainer/fine_model/G_180000.pth
COPY fine_model/D_180000.pth /MMVC_Trainer/fine_model/D_180000.pth # COPY fine_model/D_180000.pth /MMVC_Trainer/fine_model/D_180000.pth
### Copy from base ### Copy from base
COPY --from=base --chmod=777 /usr/local/lib/python3.9/dist-packages /usr/local/lib/python3.9/dist-packages COPY --from=base --chmod=777 /usr/local/lib/python3.9/dist-packages /usr/local/lib/python3.9/dist-packages
### Copy from frontend # ### Copy from frontend
##### MMVC Trainer # ##### MMVC Trainer
COPY --from=front --chmod=777 /MMVC_Trainer /MMVC_Trainer # COPY --from=front --chmod=777 /MMVC_Trainer /MMVC_Trainer
RUN chmod 0777 /MMVC_Trainer # RUN chmod 0777 /MMVC_Trainer
ADD /setup.sh /MMVC_Trainer/ # ADD /setup.sh /MMVC_Trainer/
ADD /exec.sh /MMVC_Trainer/ # ADD /exec.sh /MMVC_Trainer/
##### Voice changer Internal ##### Voice changer Internal
COPY --from=front --chmod=777 /voice-changer-internal/frontend/dist /voice-changer-internal/frontend/dist COPY --from=front --chmod=777 /voice-changer-internal/frontend/dist /voice-changer-internal/frontend/dist
COPY --from=front --chmod=777 /voice-changer-internal/voice-change-service /voice-changer-internal/voice-change-service COPY --from=front --chmod=777 /voice-changer-internal/voice-change-service /voice-changer-internal/voice-change-service
RUN chmod 0777 /voice-changer-internal/voice-change-service RUN chmod 0777 /voice-changer-internal/voice-change-service
ADD /setup.sh /voice-changer-internal/voice-change-service/
ADD /exec.sh /voice-changer-internal/voice-change-service/
COPY fine_model/G_180000.pth /voice-changer-internal/voice-change-service/MMVC_Trainer/fine_model/G_180000.pth
COPY fine_model/D_180000.pth /voice-changer-internal/voice-change-service/MMVC_Trainer/fine_model/D_180000.pth
## 歴史的な経緯でsetup.shをMMVC_Trainerに置いているのでそこを起動時のWORKDIRにしている。 ## 歴史的な経緯でsetup.shをMMVC_Trainerに置いているのでそこを起動時のWORKDIRにしている。
WORKDIR /MMVC_Trainer WORKDIR /voice-changer-internal/voice-change-service
# ##### Soft VC # ##### Soft VC
# COPY --from=front /hubert /hubert # COPY --from=front /hubert /hubert

View File

@ -13,11 +13,9 @@ echo "PARAMS: $PARAMS"
# echo "VERBOSE: $VERBOSE" # echo "VERBOSE: $VERBOSE"
echo "------" echo "------"
cd /voice-changer-internal/voice-change-service
# 起動 # 起動
if [ "${MODE}" = "MMVC" ] ; then if [ "${MODE}" = "MMVC" ] ; then
cd /voice-changer-internal/voice-change-service
if [[ -e /resources/setting.json ]]; then if [[ -e /resources/setting.json ]]; then
echo "指定された設定(setting.json)を使用します。" echo "指定された設定(setting.json)を使用します。"
cp /resources/setting.json ../frontend/dist/assets/setting.json cp /resources/setting.json ../frontend/dist/assets/setting.json
@ -30,7 +28,6 @@ if [ "${MODE}" = "MMVC" ] ; then
python3 MMVCServerSIO.py -t MMVC $PARAMS #2>stderr.txt python3 MMVCServerSIO.py -t MMVC $PARAMS #2>stderr.txt
elif [ "${MODE}" = "TRAIN" ] ; then elif [ "${MODE}" = "TRAIN" ] ; then
cd /voice-changer-internal/voice-change-service
python3 -m tensorboard.main --logdir /MMVC_Trainer/logs --port 6006 --host 0.0.0.0 & python3 -m tensorboard.main --logdir /MMVC_Trainer/logs --port 6006 --host 0.0.0.0 &
python3 MMVCServerSIO.py -t TRAIN $PARAMS python3 MMVCServerSIO.py -t TRAIN $PARAMS
fi fi

File diff suppressed because one or more lines are too long

View File

@ -5,12 +5,6 @@
(c) 2013-2017 Mozilla, Apache License 2.0 (c) 2013-2017 Mozilla, Apache License 2.0
*/ */
/*!
* Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
* Copyright 2022 Fonticons, Inc.
*/
/*! /*!
* The buffer module from node.js, for the browser. * The buffer module from node.js, for the browser.
* *

72
misc/requirements.txt Normal file
View File

@ -0,0 +1,72 @@
anyio==3.6.2
appdirs==1.4.4
attrs==22.1.0
audioread==3.0.0
Babel==2.11.0
bidict==0.22.0
certifi @ file:///private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_4d2o0arbv6/croot/certifi_1665076671099/work/certifi
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
clldutils==3.15.0
colorama==0.4.6
colorlog==6.7.0
cryptography==38.0.4
csvw==3.1.3
Cython==0.29.32
decorator==5.1.1
dlinfo==1.2.1
fastapi==0.88.0
h11==0.14.0
idna==3.4
importlib-metadata==5.1.0
isodate==0.6.1
joblib==1.2.0
jsonschema==4.17.3
language-tags==1.1.0
librosa==0.9.2
llvmlite==0.39.1
lxml==4.9.1
Markdown==3.4.1
numba==0.56.4
numpy==1.23.5
packaging==22.0
phonemizer==3.2.1
pooch==1.6.0
py==1.11.0
pycparser==2.21
pydantic==1.10.2
pylatexenc==2.10
pyOpenSSL==22.1.0
pyparsing==3.0.9
pyrsistent==0.19.2
python-dateutil==2.8.2
python-engineio==4.3.4
python-multipart==0.0.5
python-socketio==5.7.2
pytz==2022.6
rdflib==6.2.0
regex==2022.10.31
requests==2.28.1
resampy==0.4.2
retry==0.9.2
rfc3986==1.5.0
scikit-learn==1.2.0
scipy==1.9.3
segments==2.2.1
six==1.16.0
sniffio==1.3.0
soundfile==0.11.0
starlette==0.22.0
tabulate==0.9.0
threadpoolctl==3.1.0
torch==1.13.0
torchaudio==0.13.0
tqdm==4.64.1
typing_extensions==4.4.0
Unidecode==1.3.6
uritemplate==4.1.1
urllib3==1.26.13
uvicorn==0.20.0
websockets==10.4
zipp==3.11.0

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -eu set -eu
DOCKER_IMAGE=dannadori/voice-changer:20221114_095352 DOCKER_IMAGE=dannadori/voice-changer:20221209_124332
# DOCKER_IMAGE=voice-changer # DOCKER_IMAGE=voice-changer
if [ $# = 0 ]; then if [ $# = 0 ]; then