Merge pull request #66 from w-okada/dev

update
This commit is contained in:
w-okada 2022-10-03 00:17:17 +09:00 committed by GitHub
commit 9952c0d32e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 737 additions and 285 deletions

View File

@ -1,6 +1,6 @@
import eventlet
import socketio
import sys,os , math, struct, argparse
import sys,os , math, struct, argparse, logging
from distutils.util import strtobool
from datetime import datetime
from OpenSSL import SSL, crypto
@ -44,7 +44,7 @@ class MyCustomNamespace(socketio.Namespace):
print('[{}] connet sid : {}'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S') , sid))
def on_request_message(self, sid, msg):
print("Processing Request...")
# print("Processing Request...")
gpu = int(msg[0])
srcId = int(msg[1])
dstId = int(msg[2])
@ -90,7 +90,7 @@ class MyCustomNamespace(socketio.Namespace):
def setupArgParser():
parser = argparse.ArgumentParser()
parser.add_argument("-p", type=int, required=True, help="port")
parser.add_argument("-p", type=int, default=8080, help="port")
parser.add_argument("--https", type=strtobool, default=False, help="use https")
parser.add_argument("--httpsKey", type=str, default="ssl.key", help="path for the key of https")
parser.add_argument("--httpsCert", type=str, default="ssl.cert", help="path for the cert of https")
@ -120,13 +120,34 @@ def create_self_signed_cert(certfile, keyfile, certargs, cert_dir="."):
open(K_F, "wb").write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))
def printMessage(message, level=0):
if level == 0:
print(f"\033[17m{message}\033[0m")
elif level == 1:
print(f"\033[34m {message}\033[0m")
elif level == 2:
print(f"\033[32m {message}\033[0m")
else:
print(f"\033[47m {message}\033[0m")
if __name__ == '__main__':
parser = setupArgParser()
args = parser.parse_args()
PORT = args.p
print(f"start... PORT:{PORT}")
if args.https and args.httpsSelfSigned == 1:
printMessage(f"Start SoftVC SocketIO Server", level=0)
if os.environ["EX_PORT"]:
EX_PORT = os.environ["EX_PORT"]
printMessage(f"External_Port:{EX_PORT} Internal_Port:{PORT}", level=1)
else:
printMessage(f"Internal_Port:{PORT}", level=1)
if os.environ["EX_IP"]:
EX_IP = os.environ["EX_IP"]
printMessage(f"External_IP:{EX_IP}", level=1)
if args.https == 1 and args.httpsSelfSigned == 1:
# HTTPS(おれおれ証明書生成)
os.makedirs("./key", exist_ok=True)
key_base_name = f"{datetime.now().strftime('%Y%m%d_%H%M%S')}"
@ -140,15 +161,34 @@ if __name__ == '__main__':
"Org. Unit": "F"}, cert_dir="./key")
key_path = os.path.join("./key", keyname)
cert_path = os.path.join("./key", certname)
print(f"protocol: HTTPS(self-signed), key:{key_path}, cert:{cert_path}")
elif args.https and args.httpsSelfSigned == 0:
printMessage(f"protocol: HTTPS(self-signed), key:{key_path}, cert:{cert_path}", level=1)
elif args.https == 1 and args.httpsSelfSigned == 0:
# HTTPS
key_path = args.httpsKey
cert_path = args.httpsCert
print(f"protocol: HTTPS, key:{key_path}, cert:{cert_path}")
printMessage(f"protocol: HTTPS, key:{key_path}, cert:{cert_path}", level=1)
else:
# HTTP
print("protocol: HTTP")
printMessage(f"protocol: HTTP", level=1)
# アドレス表示
if args.https == 1:
printMessage(f"open https://<IP>:<PORT>/ with your browser.", level=0)
else:
printMessage(f"open http://<IP>:<PORT>/ with your browser.", level=0)
if EX_PORT and EX_IP and args.https == 1:
printMessage(f"In many cases it is one of the following", level=1)
printMessage(f"https://localhost:{EX_PORT}/", level=1)
for ip in EX_IP.strip().split(" "):
printMessage(f"https://{ip}:{EX_PORT}/", level=1)
elif EX_PORT and EX_IP and args.https == 0:
printMessage(f"In many cases it is one of the following", level=1)
printMessage(f"http://localhost:{EX_PORT}/", level=1)
# for ip in EX_IP.strip().split(" "):
# print(f" http://{ip}:{EX_PORT}/")
# SocketIOセットアップ
sio = socketio.Server(cors_allowed_origins='*')
@ -158,6 +198,13 @@ if __name__ == '__main__':
'/': '../frontend/dist/index.html',
})
### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?
# logger = logging.getLogger("logger")
# logger.propagate=False
# handler = logging.FileHandler(filename="logger.log")
# logger.addHandler(handler)
if args.https:
# HTTPS サーバ起動
sslWrapper = eventlet.wrap_ssl(
@ -166,9 +213,13 @@ if __name__ == '__main__':
keyfile=key_path,
# server_side=True
)
### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?
# eventlet.wsgi.server(sslWrapper, app, log=logger)
eventlet.wsgi.server(sslWrapper, app)
else:
# HTTP サーバ起動
### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?
# eventlet.wsgi.server(eventlet.listen(('0.0.0.0',int(PORT))), app, log=logger)
eventlet.wsgi.server(eventlet.listen(('0.0.0.0',int(PORT))), app)

View File

@ -1,6 +1,6 @@
import eventlet
import socketio
import sys, os, struct, argparse
import sys, os, struct, argparse, logging
from distutils.util import strtobool
from datetime import datetime
from OpenSSL import SSL, crypto
@ -80,7 +80,7 @@ class MyCustomNamespace(socketio.Namespace):
def setupArgParser():
parser = argparse.ArgumentParser()
parser.add_argument("-p", type=int, required=True, help="port")
parser.add_argument("-p", type=int, default=8080, help="port")
parser.add_argument("-c", type=str, required=True, help="path for the config.json")
parser.add_argument("-m", type=str, required=True, help="path for the model file")
parser.add_argument("--https", type=strtobool, default=False, help="use https")
@ -112,13 +112,35 @@ def create_self_signed_cert(certfile, keyfile, certargs, cert_dir="."):
open(K_F, "wb").write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))
def printMessage(message, level=0):
if level == 0:
print(f"\033[17m{message}\033[0m")
elif level == 1:
print(f"\033[34m {message}\033[0m")
elif level == 2:
print(f"\033[32m {message}\033[0m")
else:
print(f"\033[47m {message}\033[0m")
if __name__ == '__main__':
parser = setupArgParser()
args = parser.parse_args()
PORT = args.p
CONFIG = args.c
MODEL = args.m
print(f"start... PORT:{PORT}, CONFIG:{CONFIG}, MODEL:{MODEL}")
printMessage(f"Start MMVC SocketIO Server", level=0)
printMessage(f"CONFIG:{CONFIG}, MODEL:{MODEL}", level=1)
if os.environ["EX_PORT"]:
EX_PORT = os.environ["EX_PORT"]
printMessage(f"External_Port:{EX_PORT} Internal_Port:{PORT}", level=1)
else:
printMessage(f"Internal_Port:{PORT}", level=1)
if os.environ["EX_IP"]:
EX_IP = os.environ["EX_IP"]
printMessage(f"External_IP:{EX_IP}", level=1)
if args.https and args.httpsSelfSigned == 1:
# HTTPS(おれおれ証明書生成)
@ -134,15 +156,32 @@ if __name__ == '__main__':
"Org. Unit": "F"}, cert_dir="./key")
key_path = os.path.join("./key", keyname)
cert_path = os.path.join("./key", certname)
print(f"protocol: HTTPS(self-signed), key:{key_path}, cert:{cert_path}")
printMessage(f"protocol: HTTPS(self-signed), key:{key_path}, cert:{cert_path}", level=1)
elif args.https and args.httpsSelfSigned == 0:
# HTTPS
key_path = args.httpsKey
cert_path = args.httpsCert
print(f"protocol: HTTPS, key:{key_path}, cert:{cert_path}")
printMessage(f"protocol: HTTPS, key:{key_path}, cert:{cert_path}", level=1)
else:
# HTTP
print("protocol: HTTP")
printMessage(f"protocol: HTTP", level=1)
# アドレス表示
if args.https == 1:
printMessage(f"open https://<IP>:<PORT>/ with your browser.", level=0)
else:
printMessage(f"open http://<IP>:<PORT>/ with your browser.", level=0)
if EX_PORT and EX_IP and args.https == 1:
printMessage(f"In many cases it is one of the following", level=1)
printMessage(f"https://localhost:{EX_PORT}/", level=1)
for ip in EX_IP.strip().split(" "):
printMessage(f"https://{ip}:{EX_PORT}/", level=1)
elif EX_PORT and EX_IP and args.https == 0:
printMessage(f"In many cases it is one of the following", level=1)
printMessage(f"http://localhost:{EX_PORT}/", level=1)
# for ip in EX_IP.strip().split(" "):
# print(f" http://{ip}:{EX_PORT}/")
# SocketIOセットアップ
@ -153,6 +192,13 @@ if __name__ == '__main__':
'/': '../frontend/dist/index.html',
})
### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?
# logger = logging.getLogger("logger")
# logger.propagate=False
# handler = logging.FileHandler(filename="logger.log")
# logger.addHandler(handler)
if args.https:
# HTTPS サーバ起動
sslWrapper = eventlet.wrap_ssl(
@ -161,8 +207,12 @@ if __name__ == '__main__':
keyfile=key_path,
# server_side=True
)
### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?
# eventlet.wsgi.server(sslWrapper, app, log=logger)
eventlet.wsgi.server(sslWrapper, app)
else:
# HTTP サーバ起動
### log を設定すると通常出力されないログが取得できるようだ。(ログ出力抑制には役立たない?
# eventlet.wsgi.server(eventlet.listen(('0.0.0.0',int(PORT))), app, log=logger)
eventlet.wsgi.server(eventlet.listen(('0.0.0.0',int(PORT))), app)

View File

@ -1,16 +1,11 @@
#!/bin/bash
cp -r /resources/* .
TYPE=$1
CONFIG=$2
MODEL=$3
PARAMS=${@:2:($#-1)}
echo type: $TYPE
echo config: $CONFIG
echo model: $MODEL
cp -r /resources/* .
echo $TYPE
echo $PARAMS
## Config 設置
if [[ -e ./setting.json ]]; then
@ -26,17 +21,23 @@ else
fi
fi
# 起動
if [ "${TYPE}" = "SOFT_VC" ] ; then
echo "SOFT_VCを起動します"
python3 SoftVcServerSIO.py -p 8080 --https True --httpsSelfSigned True
python3 SoftVcServerSIO.py $PARAMS 2>stderr.txt
elif [ "${TYPE}" = "SOFT_VC_VERBOSE" ] ; then
echo "SOFT_VCを起動します(verbose)"
python3 SoftVcServerSIO.py $PARAMS
elif [ "${TYPE}" = "SOFT_VC_FAST_API" ] ; then
echo "SOFT_VC_FAST_APIを起動します"
python3 SoftVcServerFastAPI.py 8080 docker
else
elif [ "${TYPE}" = "MMVC" ] ; then
echo "MMVCを起動します"
python3 serverSIO.py -p 8080 -c $CONFIG -m $MODEL --https True --httpsSelfSigned True
python3 serverSIO.py $PARAMS 2>stderr.txt
elif [ "${TYPE}" = "MMVC_VERBOSE" ] ; then
echo "MMVCを起動します(verbose)"
python3 serverSIO.py $PARAMS
fi

425
start2.sh
View File

@ -1,163 +1,314 @@
#!/bin/bash
# 参考:https://programwiz.org/2022/03/22/how-to-write-shell-script-for-option-parsing/
DOCKER_IMAGE=dannadori/voice-changer:20220923_173952
TENSORBOARD_PORT=6006
# VOICE_CHANGER_PORT=8080
set -eu
echo "------"
echo "$@"
echo "------"
usage() {
echo "
usage:
For training
$0 [-t] -n <exp_name> [-b batch_size] [-r]
-t: トレーニングモードで実行する場合に指定してください。(train)
-n: トレーニングの名前です。(name)
-b: バッチサイズです。(batchsize)
-r: トレーニング再開の場合に指定してください。(resume)
For changing voice
$0 [-v] [-c config] [-m model] [-g on/off]
-v: ボイスチェンジャーモードで実行する場合に指定してください。(voice changer)
-c: トレーニングで使用したConfigのファイル名です。(config)
-m: トレーニング済みのモデルのファイル名です。(model)
-g: GPU使用/不使用。デフォルトはonなのでGPUを使う場合は指定不要。(gpu)
-p: port番号
For help
$0 [-h]
-h: show this help
" >&2
}
warn () {
echo "! ! ! $1 ! ! !"
exit 1
}
DOCKER_IMAGE=dannadori/voice-changer:20221003_001311
#DOCKER_IMAGE=voice-changer
training_flag=false
name=999_exp
batch_size=10
resume_flag=false
MODE=$1
PARAMS=${@:2:($#-1)}
voice_change_flag=false
config=
model=
gpu=on
port=8080
escape_flag=false
### DEFAULT VAR ###
DEFAULT_EX_PORT=18888
DEFAULT_USE_GPU=on # on|off
DEFAULT_VERBOSE=off # on|off
# オプション解析
while getopts tn:b:rvc:m:g:p:hx OPT; do
case $OPT in
t)
training_flag=true
;;
n)
name="$OPTARG"
;;
b)
batch_size="$OPTARG"
;;
r)
resume_flag=true
;;
v)
voice_change_flag=true
;;
c)
config="$OPTARG"
;;
m)
model="$OPTARG"
;;
g)
gpu="$OPTARG"
;;
p)
port="$OPTARG"
;;
h | \?)
usage && exit 1
;;
x)
escape_flag=true
esac
done
### ENV VAR ###
EX_PORT=${EX_PORT:-${DEFAULT_EX_PORT}}
USE_GPU=${USE_GPU:-${DEFAULT_USE_GPU}}
VERBOSE=${VERBOSE:-${DEFAULT_VERBOSE}}
#echo $EX_PORT $USE_GPU $VERBOSE
### INTERNAL SETTING ###
TENSORBOARD_PORT=6006
SIO_PORT=8080
# モード解析
if $training_flag && $voice_change_flag; then
warn "-tトレーニングモード と -vボイチェンモードは同時に指定できません。"
elif $training_flag; then
echo "■■■ ト レ ー ニ ン グ モ ー ド ■■■"
elif $voice_change_flag; then
echo "■■■ ボ イ チ ェ ン モ ー ド ■■■"
elif $escape_flag; then
/bin/bash
else
warn "-tトレーニングモード と -vボイチェンモードのいずれかを指定してください。"
fi
###
if [ "${MODE}" = "MMVC_TRAIN" ]; then
echo "トレーニングを開始します"
docker run -it --gpus all --shm-size=128M \
-v `pwd`/exp/${name}/dataset:/MMVC_Trainer/dataset \
-v `pwd`/exp/${name}/logs:/MMVC_Trainer/logs \
-v `pwd`/exp/${name}/filelists:/MMVC_Trainer/filelists \
-v `pwd`/vc_resources:/resources \
-e LOCAL_UID=$(id -u $USER) \
-e LOCAL_GID=$(id -g $USER) \
-e EX_IP="`hostname -I`" \
-e EX_PORT=${EX_PORT} \
-e VERBOSE=${VERBOSE} \
-p ${EX_PORT}:6006 $DOCKER_IMAGE "$@"
if $training_flag; then
if $resume_flag; then
echo "トレーニングを再開します"
docker run -it --gpus all --shm-size=128M \
-v `pwd`/exp/${name}/dataset:/MMVC_Trainer/dataset \
-v `pwd`/exp/${name}/logs:/MMVC_Trainer/logs \
-v `pwd`/exp/${name}/filelists:/MMVC_Trainer/filelists \
-v `pwd`/vc_resources:/resources \
-e LOCAL_UID=$(id -u $USER) \
-e LOCAL_GID=$(id -g $USER) \
-p ${TENSORBOARD_PORT}:6006 $DOCKER_IMAGE -t -b ${batch_size} -r
else
echo "トレーニングを開始します"
docker run -it --gpus all --shm-size=128M \
-v `pwd`/exp/${name}/dataset:/MMVC_Trainer/dataset \
-v `pwd`/exp/${name}/logs:/MMVC_Trainer/logs \
-v `pwd`/exp/${name}/filelists:/MMVC_Trainer/filelists \
-v `pwd`/vc_resources:/resources \
-e LOCAL_UID=$(id -u $USER) \
-e LOCAL_GID=$(id -g $USER) \
-p ${TENSORBOARD_PORT}:6006 $DOCKER_IMAGE -t -b ${batch_size}
fi
fi
if $voice_change_flag; then
if [[ -z "$config" ]]; then
warn "コンフィグファイル(-c)を指定してください"
fi
if [[ -z "$model" ]]; then
warn "モデルファイル(-m)を指定してください"
fi
if [ "${gpu}" = "on" ]; then
echo "GPUをマウントして起動します。"
elif [ "${MODE}" = "MMVC" ]; then
if [ "${USE_GPU}" = "on" ]; then
echo "MMVCを起動します(with gpu)"
docker run -it --gpus all --shm-size=128M \
-v `pwd`/vc_resources:/resources \
-e LOCAL_UID=$(id -u $USER) \
-e LOCAL_GID=$(id -g $USER) \
-p ${port}:8080 $DOCKER_IMAGE -v -c ${config} -m ${model}
elif [ "${gpu}" = "off" ]; then
echo "CPUのみで稼働します。GPUは使用できません。"
-e EX_IP="`hostname -I`" \
-e EX_PORT=${EX_PORT} \
-e VERBOSE=${VERBOSE} \
-p ${EX_PORT}:8080 $DOCKER_IMAGE "$@"
else
echo "MMVCを起動します(only cpu)"
docker run -it --shm-size=128M \
-v `pwd`/vc_resources:/resources \
-e LOCAL_UID=$(id -u $USER) \
-e LOCAL_GID=$(id -g $USER) \
-p ${port}:8080 $DOCKER_IMAGE -v -c ${config} -m ${model}
else
echo ${gpu}
warn "-g は onかoffで指定して下さい。"
-e EX_IP="`hostname -I`" \
-e EX_PORT=${EX_PORT} \
-e VERBOSE=${VERBOSE} \
-p ${EX_PORT}:8080 $DOCKER_IMAGE "$@"
# docker run -it --shm-size=128M \
# -v `pwd`/vc_resources:/resources \
# -e LOCAL_UID=$(id -u $USER) \
# -e LOCAL_GID=$(id -g $USER) \
# -e EX_IP="`hostname -I`" \
# -e EX_PORT=${EX_PORT} \
# -e VERBOSE=${VERBOSE} \
# --entrypoint="" \
# -p ${EX_PORT}:8080 $DOCKER_IMAGE /bin/bash
fi
elif [ "${MODE}" = "SOFT_VC" ]; then
if [ "${USE_GPU}" = "on" ]; then
echo "Start Soft-vc"
docker run -it --gpus all --shm-size=128M \
-v `pwd`/vc_resources:/resources \
-e LOCAL_UID=$(id -u $USER) \
-e LOCAL_GID=$(id -g $USER) \
-e EX_IP="`hostname -I`" \
-e EX_PORT=${EX_PORT} \
-e VERBOSE=${VERBOSE} \
-p ${EX_PORT}:8080 $DOCKER_IMAGE "$@"
else
echo "Start Soft-vc withou GPU is not supported"
fi
else
echo "
usage:
$0 <MODE> <params...>
MODE: select one of ['MMVC_TRAIN', 'MMVC', 'SOFT_VC']
" >&2
fi
# echo $EX_PORT
# echo "------"
# echo "$@"
# echo "------"
# # usage() {
# # echo "
# # usage:
# # For training
# # $0 [-t] -n <exp_name> [-b batch_size] [-r]
# # -t: トレーニングモードで実行する場合に指定してください。(train)
# # -n: トレーニングの名前です。(name)
# # -b: バッチサイズです。(batchsize)
# # -r: トレーニング再開の場合に指定してください。(resume)
# # For changing voice
# # $0 [-v] [-c config] [-m model] [-g on/off]
# # -v: ボイスチェンジャーモードで実行する場合に指定してください。(voice changer)
# # -c: トレーニングで使用したConfigのファイル名です。(config)
# # -m: トレーニング済みのモデルのファイル名です。(model)
# # -g: GPU使用/不使用。デフォルトはonなのでGPUを使う場合は指定不要。(gpu)
# # -p: port番号
# # For help
# # $0 [-h]
# # -h: show this help
# # " >&2
# # }
# # warn () {
# # echo "! ! ! $1 ! ! !"
# # exit 1
# # }
# # training_flag=false
# # name=999_exp
# # batch_size=10
# # resume_flag=false
# # voice_change_flag=false
# # config=
# # model=
# # gpu=on
# # port=8080
# # escape_flag=false
# # # オプション解析
# # while getopts tn:b:rvc:m:g:p:hx OPT; do
# # case $OPT in
# # t)
# # training_flag=true
# # ;;
# # n)
# # name="$OPTARG"
# # ;;
# # b)
# # batch_size="$OPTARG"
# # ;;
# # r)
# # resume_flag=true
# # ;;
# # v)
# # voice_change_flag=true
# # ;;
# # c)
# # config="$OPTARG"
# # ;;
# # m)
# # model="$OPTARG"
# # ;;
# # g)
# # gpu="$OPTARG"
# # ;;
# # p)
# # port="$OPTARG"
# # ;;
# # h | \?)
# # usage && exit 1
# # ;;
# # x)
# # escape_flag=true
# # esac
# # done
# # # モード解析
# # if $training_flag && $voice_change_flag; then
# # warn "-tトレーニングモード と -vボイチェンモードは同時に指定できません。"
# # elif $training_flag; then
# # echo "■■■ ト レ ー ニ ン グ モ ー ド ■■■"
# # elif $voice_change_flag; then
# # echo "■■■ ボ イ チ ェ ン モ ー ド ■■■"
# # elif $escape_flag; then
# # /bin/bash
# # else
# # warn "-tトレーニングモード と -vボイチェンモードのいずれかを指定してください。"
# # fi
# if [ "${MODE}" = "MMVC_TRAIN_INITIAL" ]; then
# echo "トレーニングを開始します"
# elif [ "${MODE}" = "MMVC" ]; then
# echo "MMVCを起動します"
# docker run -it --gpus all --shm-size=128M \
# -v `pwd`/vc_resources:/resources \
# -e LOCAL_UID=$(id -u $USER) \
# -e LOCAL_GID=$(id -g $USER) \
# -e EX_IP="`hostname -I`" \
# -e EX_PORT=${port} \
# -p ${port}:8080 $DOCKER_IMAGE -v -c ${config} -m ${model}
# elif [ "${MODE}" = "MMVC_VERBOSE" ]; then
# echo "MMVCを起動します(verbose)"
# elif [ "${MODE}" = "MMVC_CPU" ]; then
# echo "MMVCを起動します(CPU)"
# elif [ "${MODE}" = "MMVC_CPU_VERBOSE" ]; then
# echo "MMVCを起動します(CPU)(verbose)"
# elif [ "${MODE}" = "SOFT_VC" ]; then
# echo "Start Soft-vc"
# elif [ "${MODE}" = "SOFT_VC_VERBOSE" ]; then
# echo "Start Soft-vc(verbose)"
# else
# echo "
# usage:
# $0 <MODE> <params...>
# EX_PORT:
# MODE: one of ['MMVC_TRAIN', 'MMVC', 'SOFT_VC']
# For 'MMVC_TRAIN':
# $0 MMVC_TRAIN_INITIAL -n <exp_name> [-b batch_size] [-r]
# -n: トレーニングの名前です。(name)
# -b: バッチサイズです。(batchsize)
# -r: トレーニング再開の場合に指定してください。(resume)
# For 'MMVC'
# $0 MMVC [-c config] [-m model] [-g on/off] [-p port] [-v]
# -c: トレーニングで使用したConfigのファイル名です。(config)
# -m: トレーニング済みのモデルのファイル名です。(model)
# -g: GPU使用/不使用。デフォルトはonなのでGPUを使う場合は指定不要。(gpu)
# -p: Docker からExposeするport番号
# -v: verbose
# For 'SOFT_VC'
# $0 SOFT_VC [-c config] [-m model] [-g on/off]
# -p: port exposed from docker container.
# -v: verbose
# " >&2
# fi
# # if $training_flag; then
# # if $resume_flag; then
# # echo "トレーニングを再開します"
# # docker run -it --gpus all --shm-size=128M \
# # -v `pwd`/exp/${name}/dataset:/MMVC_Trainer/dataset \
# # -v `pwd`/exp/${name}/logs:/MMVC_Trainer/logs \
# # -v `pwd`/exp/${name}/filelists:/MMVC_Trainer/filelists \
# # -v `pwd`/vc_resources:/resources \
# # -e LOCAL_UID=$(id -u $USER) \
# # -e LOCAL_GID=$(id -g $USER) \
# # -p ${TENSORBOARD_PORT}:6006 $DOCKER_IMAGE -t -b ${batch_size} -r
# # else
# # echo "トレーニングを開始します"
# # docker run -it --gpus all --shm-size=128M \
# # -v `pwd`/exp/${name}/dataset:/MMVC_Trainer/dataset \
# # -v `pwd`/exp/${name}/logs:/MMVC_Trainer/logs \
# # -v `pwd`/exp/${name}/filelists:/MMVC_Trainer/filelists \
# # -v `pwd`/vc_resources:/resources \
# # -e LOCAL_UID=$(id -u $USER) \
# # -e LOCAL_GID=$(id -g $USER) \
# # -p ${TENSORBOARD_PORT}:6006 $DOCKER_IMAGE -t -b ${batch_size}
# # fi
# # fi
# # if $voice_change_flag; then
# # if [[ -z "$config" ]]; then
# # warn "コンフィグファイル(-c)を指定してください"
# # fi
# # if [[ -z "$model" ]]; then
# # warn "モデルファイル(-m)を指定してください"
# # fi
# # if [ "${gpu}" = "on" ]; then
# # echo "GPUをマウントして起動します。"
# # docker run -it --gpus all --shm-size=128M \
# # -v `pwd`/vc_resources:/resources \
# # -e LOCAL_UID=$(id -u $USER) \
# # -e LOCAL_GID=$(id -g $USER) \
# # -e EX_IP="`hostname -I`" \
# # -e EX_PORT=${port} \
# # -p ${port}:8080 $DOCKER_IMAGE -v -c ${config} -m ${model}
# # elif [ "${gpu}" = "off" ]; then
# # echo "CPUのみで稼働します。GPUは使用できません。"
# # docker run -it --shm-size=128M \
# # -v `pwd`/vc_resources:/resources \
# # -e LOCAL_UID=$(id -u $USER) \
# # -e LOCAL_GID=$(id -g $USER) \
# # -e EX_IP="`hostname -I`" \
# # -e EX_PORT=${port} \
# # -p ${port}:8080 $DOCKER_IMAGE -v -c ${config} -m ${model}
# # else
# # echo ${gpu}
# # warn "-g は onかoffで指定して下さい。"
# # fi
# # fi

View File

@ -1,4 +1,4 @@
FROM dannadori/voice-changer-internal:20220923_153015 as front
FROM dannadori/voice-changer-internal:20221002_193031 as front
FROM debian:bullseye-slim as base
ARG DEBIAN_FRONTEND=noninteractive
@ -60,5 +60,13 @@ ADD /exec.sh /MMVC_Trainer/
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
RUN chmod 0777 /voice-changer-internal/voice-change-service
COPY --from=front /hubert /hubert
COPY --from=front /acoustic-model /acoustic-model
COPY --from=front /hifigan /hifigan
COPY --from=front /models /models
ENTRYPOINT ["/bin/bash", "setup.sh"]
CMD [ "-h"]

View File

@ -4,130 +4,189 @@
set -eu
MODE=$1
PARAMS=${@:2:($#-1)}
echo "------"
echo "$@"
echo "$MODE"
echo "PARAMS: $PARAMS"
echo "VERBOSE: $VERBOSE"
echo "------"
usage() {
echo "
usage:
For training
$0 [-t] [-b batch_size] [-r]
-t: flag for training mode
-b: batch_size.
-r: flag for resuming training.
For changing voice
$0 [-v] [-c config] [-m model]
-v: flag for voice change mode
-c: config
-m: model name
For help
$0 [-h]
-h: show this help
" >&2
}
warn () {
echo "! ! ! $1 ! ! !"
exit 1
}
training_flag=false
batch_size=10
resume_flag=false
voice_change_flag=false
config=
model=
escape_flag=false
# オプション解析
while getopts tb:rvc:m:hx OPT; do
case $OPT in
t)
training_flag=true
;;
b)
batch_size="$OPTARG"
;;
r)
resume_flag=true
;;
v)
voice_change_flag=true
;;
c)
config="$OPTARG"
;;
m)
model="$OPTARG"
;;
h | \?)
usage && exit 1
;;
x)
escape_flag=true
esac
done
# ## コマンドライン引数から、オプション引数分を削除
# # shift $((OPTIND - 1))
# # モード解析
# if $training_flag && $voice_change_flag; then
# warn "-tトレーニングモード と -vボイチェンモードは同時に指定できません。"
# exit 1
# elif $training_flag; then
# echo "■■■ ト レ ー ニ ン グ モ ー ド ■■■"
# elif $voice_change_flag; then
# echo "■■■ ボ イ チ ェ ン モ ー ド ■■■"
# elif $escape_flag; then
# /bin/bash
# else
# warn "-tトレーニングモード と -vボイチェンモードのいずれかを指定してください。"
# exit 1
# fi
if $training_flag; then
python3 create_dataset_jtalk.py -f train_config -s 24000 -m dataset/multi_speaker_correspondence.txt
# date_tag=`date +%Y%m%d%H%M%S`
sed -ie 's/80000/8000/' train_ms.py
sed -ie "s/\"batch_size\": 10/\"batch_size\": $batch_size/" configs/train_config.json
sed -ie "s/torch.cuda.device_count()/1/" train_ms.py
python3 -m tensorboard.main --logdir logs --port 6006 --host 0.0.0.0 &
if ${resume_flag}; then
echo "トレーニング再開。バッチサイズ: ${batch_size}"
python3 train_ms.py -c configs/train_config.json -m vc
else
echo "トレーニング開始。バッチサイズ: ${batch_size}"
python3 train_ms.py -c configs/train_config.json -m vc -fg fine_model/G_180000.pth -fd fine_model/D_180000.pth
fi
fi
if $voice_change_flag; then
if [[ -z "$config" ]]; then
warn "コンフィグファイル(-c)を指定してください"
fi
if [[ -z "$model" ]]; then
warn "モデルファイル(-m)を指定してください"
fi
# 起動
if [ "${MODE}" = "SOFT_VC" ] ; then
cd /voice-changer-internal/voice-change-service
cp -r /resources/* .
if [[ -e ./setting.json ]]; then
cp ./setting.json ../frontend/dist/assets/setting.json
fi
echo "-----------!!"
echo $config $model
echo $model
python3 serverSIO.py -p 8080 -c $config -m $model --https True --httpsSelfSigned True
if [ "${VERBOSE}" = "on" ]; then
echo "SOFT_VCを起動します(verbose)"
python3 SoftVcServerSIO.py $PARAMS
else
echo "SOFT_VCを起動します"
python3 SoftVcServerSIO.py $PARAMS 2>stderr.txt
fi
elif [ "${MODE}" = "MMVC" ] ; then
cd /voice-changer-internal/voice-change-service
cp -r /resources/* .
if [[ -e ./setting.json ]]; then
cp ./setting.json ../frontend/dist/assets/setting.json
fi
if [ "${VERBOSE}" = "on" ]; then
echo "MMVCを起動します(verbose)"
python3 serverSIO.py $PARAMS
else
echo "MMVCを起動します"
python3 serverSIO.py $PARAMS 2>stderr.txt
fi
elif [ "${MODE}" = "MMVC_TRAIN" ] ; then
python3 create_dataset_jtalk.py -f train_config -s 24000 -m dataset/multi_speaker_correspondence.txt
# date_tag=`date +%Y%m%d%H%M%S`
sed -ie 's/80000/8000/' train_ms.py
sed -ie "s/\"batch_size\": 10/\"batch_size\": $batch_size/" configs/train_config.json
sed -ie "s/torch.cuda.device_count()/1/" train_ms.py
python3 -m tensorboard.main --logdir logs --port 6006 --host 0.0.0.0 &
python3 train_ms.py $PARAMS
# if ${resume_flag}; then
# echo "トレーニング再開。バッチサイズ: ${batch_size}。"
# python3 train_ms.py -c configs/train_config.json -m vc
# else
# echo "トレーニング開始。バッチサイズ: ${batch_size}。"
# python3 train_ms.py -c configs/train_config.json -m vc -fg fine_model/G_180000.pth -fd fine_model/D_180000.pth
# fi
fi
# usage() {
# echo "
# usage:
# For training
# $0 [-t] [-b batch_size] [-r]
# -t: flag for training mode
# -b: batch_size.
# -r: flag for resuming training.
# For changing voice
# $0 [-v] [-c config] [-m model]
# -v: flag for voice change mode
# -c: config
# -m: model name
# For help
# $0 [-h]
# -h: show this help
# " >&2
# }
# warn () {
# echo "! ! ! $1 ! ! !"
# exit 1
# }
# training_flag=false
# batch_size=10
# resume_flag=false
# voice_change_flag=false
# config=
# model=
# escape_flag=false
# # オプション解析
# while getopts tb:rvc:m:hx OPT; do
# case $OPT in
# t)
# training_flag=true
# ;;
# b)
# batch_size="$OPTARG"
# ;;
# r)
# resume_flag=true
# ;;
# v)
# voice_change_flag=true
# ;;
# c)
# config="$OPTARG"
# ;;
# m)
# model="$OPTARG"
# ;;
# h | \?)
# usage && exit 1
# ;;
# x)
# escape_flag=true
# esac
# done
# # ## コマンドライン引数から、オプション引数分を削除
# # # shift $((OPTIND - 1))
# # # モード解析
# # if $training_flag && $voice_change_flag; then
# # warn "-tトレーニングモード と -vボイチェンモードは同時に指定できません。"
# # exit 1
# # elif $training_flag; then
# # echo "■■■ ト レ ー ニ ン グ モ ー ド ■■■"
# # elif $voice_change_flag; then
# # echo "■■■ ボ イ チ ェ ン モ ー ド ■■■"
# # elif $escape_flag; then
# # /bin/bash
# # else
# # warn "-tトレーニングモード と -vボイチェンモードのいずれかを指定してください。"
# # exit 1
# # fi
# if $training_flag; then
# python3 create_dataset_jtalk.py -f train_config -s 24000 -m dataset/multi_speaker_correspondence.txt
# # date_tag=`date +%Y%m%d%H%M%S`
# sed -ie 's/80000/8000/' train_ms.py
# sed -ie "s/\"batch_size\": 10/\"batch_size\": $batch_size/" configs/train_config.json
# sed -ie "s/torch.cuda.device_count()/1/" train_ms.py
# python3 -m tensorboard.main --logdir logs --port 6006 --host 0.0.0.0 &
# if ${resume_flag}; then
# echo "トレーニング再開。バッチサイズ: ${batch_size}。"
# python3 train_ms.py -c configs/train_config.json -m vc
# else
# echo "トレーニング開始。バッチサイズ: ${batch_size}。"
# python3 train_ms.py -c configs/train_config.json -m vc -fg fine_model/G_180000.pth -fd fine_model/D_180000.pth
# fi
# fi
# if $voice_change_flag; then
# if [[ -z "$config" ]]; then
# warn "コンフィグファイル(-c)を指定してください"
# fi
# if [[ -z "$model" ]]; then
# warn "モデルファイル(-m)を指定してください"
# fi
# cd /voice-changer-internal/voice-change-service
# cp -r /resources/* .
# if [[ -e ./setting.json ]]; then
# cp ./setting.json ../frontend/dist/assets/setting.json
# fi
# echo "-----------!!"
# echo $config $model
# echo $model
# python3 serverSIO.py -p 8080 -c $config -m $model --https True --httpsSelfSigned True
# fi

133
trainer/exec_.sh Normal file
View File

@ -0,0 +1,133 @@
#!/bin/bash
# 参考:https://programwiz.org/2022/03/22/how-to-write-shell-script-for-option-parsing/
set -eu
echo "------"
echo "$@"
echo "------"
usage() {
echo "
usage:
For training
$0 [-t] [-b batch_size] [-r]
-t: flag for training mode
-b: batch_size.
-r: flag for resuming training.
For changing voice
$0 [-v] [-c config] [-m model]
-v: flag for voice change mode
-c: config
-m: model name
For help
$0 [-h]
-h: show this help
" >&2
}
warn () {
echo "! ! ! $1 ! ! !"
exit 1
}
training_flag=false
batch_size=10
resume_flag=false
voice_change_flag=false
config=
model=
escape_flag=false
# オプション解析
while getopts tb:rvc:m:hx OPT; do
case $OPT in
t)
training_flag=true
;;
b)
batch_size="$OPTARG"
;;
r)
resume_flag=true
;;
v)
voice_change_flag=true
;;
c)
config="$OPTARG"
;;
m)
model="$OPTARG"
;;
h | \?)
usage && exit 1
;;
x)
escape_flag=true
esac
done
# ## コマンドライン引数から、オプション引数分を削除
# # shift $((OPTIND - 1))
# # モード解析
# if $training_flag && $voice_change_flag; then
# warn "-tトレーニングモード と -vボイチェンモードは同時に指定できません。"
# exit 1
# elif $training_flag; then
# echo "■■■ ト レ ー ニ ン グ モ ー ド ■■■"
# elif $voice_change_flag; then
# echo "■■■ ボ イ チ ェ ン モ ー ド ■■■"
# elif $escape_flag; then
# /bin/bash
# else
# warn "-tトレーニングモード と -vボイチェンモードのいずれかを指定してください。"
# exit 1
# fi
if $training_flag; then
python3 create_dataset_jtalk.py -f train_config -s 24000 -m dataset/multi_speaker_correspondence.txt
# date_tag=`date +%Y%m%d%H%M%S`
sed -ie 's/80000/8000/' train_ms.py
sed -ie "s/\"batch_size\": 10/\"batch_size\": $batch_size/" configs/train_config.json
sed -ie "s/torch.cuda.device_count()/1/" train_ms.py
python3 -m tensorboard.main --logdir logs --port 6006 --host 0.0.0.0 &
if ${resume_flag}; then
echo "トレーニング再開。バッチサイズ: ${batch_size}"
python3 train_ms.py -c configs/train_config.json -m vc
else
echo "トレーニング開始。バッチサイズ: ${batch_size}"
python3 train_ms.py -c configs/train_config.json -m vc -fg fine_model/G_180000.pth -fd fine_model/D_180000.pth
fi
fi
if $voice_change_flag; then
if [[ -z "$config" ]]; then
warn "コンフィグファイル(-c)を指定してください"
fi
if [[ -z "$model" ]]; then
warn "モデルファイル(-m)を指定してください"
fi
cd /voice-changer-internal/voice-change-service
cp -r /resources/* .
if [[ -e ./setting.json ]]; then
cp ./setting.json ../frontend/dist/assets/setting.json
fi
echo "-----------!!"
echo $config $model
echo $model
python3 serverSIO.py -p 8080 -c $config -m $model --https True --httpsSelfSigned True
fi

View File

@ -8,13 +8,12 @@ set -eu
USER_ID=${LOCAL_UID:-9001}
GROUP_ID=${LOCAL_GID:-9001}
echo ""
echo "アプリケーション開始... (内部ユーザー [UID : $USER_ID, GID: $GROUP_ID]"
echo "exec with [UID : $USER_ID, GID: $GROUP_ID]"
useradd -u $USER_ID -o -m user
groupmod -g $GROUP_ID user
#su user
# echo "parameter: $@"
#echo "parameter: $@"
exec /usr/sbin/gosu user /bin/bash exec.sh "$@"
#/bin/bash