前提
awsのsagemakerにて音響モデルを用いたTTSシステムを作っています。
実現したいこと
sagemakerで音響モデルをデプロイしたいと考えています。
発生している問題・エラーメッセージ
デプロイ時に下記のエラーが繰り返し発生します。
Please specify --force/-f option to overwrite the model archive output file.
See -h/--help for more details./.sagemaker/mms/models/model
ERROR - %s already exists.
※以下、デプロイ用コード
from sagemaker import get_execution_role from sagemaker.pytorch.model import PyTorchModel role = get_execution_role() pytorch_model = PyTorchModel(model_data='s3://sagemaker-alterly/model.tar.gz', role=role, framework_version="1.3.1", py_version="py3", entry_point='inference.py') predictor = pytorch_model.deploy(instance_type='ml.t2.2xlarge', initial_instance_count=1)
※entry_pointの推論コード
iference.py
1import os 2import time 3import torch 4import pyopenjtalk 5from espnet2.bin.tts_inference import Text2Speech 6import matplotlib.pyplot as plt 7from espnet2.tasks.tts import TTSTask 8from espnet2.text.token_id_converter import TokenIDConverter 9import numpy as np 10 11import argparse 12import text_processing as texp 13import os 14 15import boto3 16 17prosodic = True 18 19model_dir = "model/" 20vocoder_dir = "vocoder/" 21CONTENT_TYPE = "text/plain" 22 23train_config = "model/config.yaml" 24model_file = "model/50epoch.pth" 25# train_config="" 26# model_file=" 27 28vocoder_tag = "parallel_wavegan/jsut_hifigan.v1" 29# ボコーダを指定 30vocoder_config = "vocoder/config.yaml" 31vocoder_file = "vocoder/50epoch.pth" 32 33 34def model_fn(model_dir): 35 print(model_dir + "config.yaml") 36 print(model_dir + "100epoch.pth") 37 model = Text2Speech.from_pretrained( 38 train_config=model_dir + "config.yaml", 39 model_file=model_dir + "100epoch.pth", 40 vocoder_tag=vocoder_tag, 41 device="cpu", 42 speed_control_alpha=1.0, 43 noise_scale=0.333, 44 noise_scale_dur=0.333, 45 ) 46 47 return model 48 49 50def input_fn(request_body, content_type=CONTENT_TYPE): 51 input_data = "あいうえお" 52 return input_data 53 54 55def predict_fn(input_data, model): 56 import torch 57 import os 58 import numpy as np 59 60 x = "デモテキスト" 61 62 # model, train_args = TTSTask.build_model_from_file( 63 # train_config, model_file, "cuda" 64 # ) 65 66 token_id_converter = TokenIDConverter( 67 token_list=model.train_args.token_list, 68 unk_symbol="<unk>", 69 ) 70 71 text = x 72 if prosodic: 73 tokens = texp.a2p(x) 74 text_ints = token_id_converter.tokens2ids(tokens) 75 text = np.array(text_ints) 76 else: 77 print("\npyopenjtalk_accent_with_pauseによる解析結果:") 78 print(texp.text2yomi(x), "\n") 79 80 # synthesis 81 with torch.no_grad(): 82 start = time.time() 83 data = model(text) 84 wav = data["wav"] 85 # print(text2speech.preprocess_fn("<dummy>",dict(text=x))["text"]) 86 rtf = (time.time() - start) / (len(wav) / model.fs) 87 print(f"RTF = {rtf:5f}") 88 89 if not os.path.isdir("generated_wav"): 90 os.makedirs("generated_wav") 91 92 # let us listen to generated samples 93 from IPython.display import display, Audio 94 import numpy as np 95 #display(Audio(wav.view(-1).cpu().numpy(), rate=text2speech.fs)) 96 #Audio(wav.view(-1).cpu().numpy(), rate=text2speech.fs) 97 np_wav = wav.view(-1).cpu().numpy() 98 99 fs = 48000 100 print("サンプリングレート", fs, "で出力します。") 101 from scipy.io.wavfile import write 102 samplerate = fs 103 t = np.linspace(0., 1., samplerate) 104 amplitude = np.iinfo(np.int16).max 105 data = amplitude * np_wav/np.max(np.abs(np_wav)) 106 write("espnet/egs2/jsut/tts1/generated_wav/"+x + 107 ".wav", samplerate, data.astype(np.int16)) 108 print("\n\n\n") 109 110 # バケットへの接続 111 s3 = boto3.resource('s3') 112 bucket = s3.Bucket('alterly-source') 113 bucket.upload_file("espnet/egs2/jsut/tts1/generated_wav/" + 114 x + ".wav", "source/"+x+".wav") 115 116 x = "exit" 117 118 119input_object = input_fn("あいうえお", "text/plain") 120model = model_fn(model_dir) 121prediction = predict_fn(input_object, model)
補足情報
こちらをmodel.tar.gzに圧縮してs3に設置しています。
急ぎの案件のため、他サイトでも相談させてもらっています。
進捗があった際にはこちらにも共有いたします。
https://ja.stackoverflow.com/questions/91142/sagemaker%e7%92%b0%e5%a2%83%e3%81%ab%e3%81%a6%e3%83%87%e3%83%97%e3%83%ad%e3%82%a4%e3%81%ab%e5%a4%b1%e6%95%97%e3%81%99%e3%82%8b
対処方法をご存知の方がいましたら、ご教授いただけますと幸いです。

回答1件
あなたの回答
tips
プレビュー