Refactor: unify invoke format of open() function
This commit is contained in:
@@ -180,7 +180,7 @@ def load_filepaths_and_text(
|
||||
list[list[str]]: ファイルパスとテキストのリスト
|
||||
"""
|
||||
|
||||
with open(filename, encoding="utf-8") as f:
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
filepaths_and_text = [line.strip().split(split) for line in f]
|
||||
return filepaths_and_text
|
||||
|
||||
@@ -249,7 +249,8 @@ def check_git_hash(model_dir_path: Union[str, Path]) -> None:
|
||||
|
||||
path = os.path.join(model_dir_path, "githash")
|
||||
if os.path.exists(path):
|
||||
saved_hash = open(path).read()
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
saved_hash = f.read()
|
||||
if saved_hash != cur_hash:
|
||||
logger.warning(
|
||||
"git hash values are different. {}(saved) != {}(current)".format(
|
||||
@@ -257,4 +258,5 @@ def check_git_hash(model_dir_path: Union[str, Path]) -> None:
|
||||
)
|
||||
)
|
||||
else:
|
||||
open(path, "w").write(cur_hash)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(cur_hash)
|
||||
|
||||
@@ -85,7 +85,7 @@ def load_checkpoint(
|
||||
else:
|
||||
model.load_state_dict(new_state_dict, strict=False)
|
||||
|
||||
logger.info("Loaded '{}' (iteration {})".format(checkpoint_path, iteration))
|
||||
logger.info(f"Loaded '{checkpoint_path}' (iteration {iteration})")
|
||||
|
||||
return model, optimizer, learning_rate, iteration
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def load_model(
|
||||
language: Languages,
|
||||
pretrained_model_name_or_path: Optional[str] = None,
|
||||
cache_dir: Optional[str] = None,
|
||||
revision: str = 'main',
|
||||
revision: str = "main",
|
||||
) -> Union[PreTrainedModel, DebertaV2Model]:
|
||||
"""
|
||||
指定された言語の BERT モデルをロードし、ロード済みの BERT モデルを返す。
|
||||
@@ -96,7 +96,7 @@ def load_tokenizer(
|
||||
language: Languages,
|
||||
pretrained_model_name_or_path: Optional[str] = None,
|
||||
cache_dir: Optional[str] = None,
|
||||
revision: str = 'main',
|
||||
revision: str = "main",
|
||||
) -> Union[PreTrainedTokenizer, PreTrainedTokenizerFast, DebertaV2Tokenizer]:
|
||||
"""
|
||||
指定された言語の BERT モデルをロードし、ロード済みの BERT トークナイザーを返す。
|
||||
|
||||
@@ -8,10 +8,11 @@ from style_bert_vits2.nlp.chinese.tone_sandhi import ToneSandhi
|
||||
from style_bert_vits2.nlp.symbols import PUNCTUATIONS
|
||||
|
||||
|
||||
__PINYIN_TO_SYMBOL_MAP = {
|
||||
line.split("\t")[0]: line.strip().split("\t")[1]
|
||||
for line in open(Path(__file__).parent / "opencpop-strict.txt").readlines()
|
||||
}
|
||||
with open(Path(__file__).parent / "opencpop-strict.txt", "r", encoding="utf-8") as f:
|
||||
__PINYIN_TO_SYMBOL_MAP = {
|
||||
line.split("\t")[0]: line.strip().split("\t")[1]
|
||||
for line in f.readlines()
|
||||
}
|
||||
|
||||
|
||||
def g2p(text: str) -> tuple[list[str], list[int], list[int]]:
|
||||
|
||||
@@ -20,7 +20,7 @@ def get_dict() -> dict[str, list[list[str]]]:
|
||||
def read_dict() -> dict[str, list[list[str]]]:
|
||||
g2p_dict = {}
|
||||
start_line = 49
|
||||
with open(CMU_DICT_PATH) as f:
|
||||
with open(CMU_DICT_PATH, "r", encoding="utf-8") as f:
|
||||
line = f.readline()
|
||||
line_index = 1
|
||||
while line:
|
||||
|
||||
Reference in New Issue
Block a user