Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TTS/speaker_encoder/utils/prepare_voxceleb.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def download_and_extract(directory, subset, urls):
extract_path = zip_filepath.strip(".zip")

# check zip file md5sum
md5 = hashlib.md5(open(zip_filepath, 'rb').read()).hexdigest()
md5 = hashlib.md5(open(zip_filepath, 'rb').read(), usedforsecurity=False).hexdigest()
if md5 != MD5SUM[subset]:
raise ValueError("md5sum of %s mismatch" % zip_filepath)

Expand Down
11 changes: 10 additions & 1 deletion TTS/tts/tf/utils/generic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ def save_checkpoint(model, optimizer, current_step, epoch, r, output_path, **kwa
pickle.dump(state, open(output_path, 'wb'))


class SafeUnpickler(pickle.Unpickler):
def find_class(self, module, name):
if module == "builtins" and name in {"dict", "list", "tuple", "set", "int", "float", "str", "bytes", "bool"}:
return super().find_class(module, name)
if "numpy" in module:
return super().find_class(module, name)
raise pickle.UnpicklingError(f"Unsafe global {module}.{name}")


def load_checkpoint(model, checkpoint_path):
checkpoint = pickle.load(open(checkpoint_path, 'rb'))
checkpoint = SafeUnpickler(open(checkpoint_path, 'rb')).load()
chkp_var_dict = {var.name: var.numpy() for var in checkpoint['model']}
tf_vars = model.weights
for tf_var in tf_vars:
Expand Down
11 changes: 10 additions & 1 deletion TTS/tts/tf/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ def save_checkpoint(model, optimizer, current_step, epoch, r, output_path, **kwa
pickle.dump(state, open(output_path, 'wb'))


class SafeUnpickler(pickle.Unpickler):
def find_class(self, module, name):
if module == "builtins" and name in {"dict", "list", "tuple", "set", "int", "float", "str", "bytes", "bool"}:
return super().find_class(module, name)
if "numpy" in module:
return super().find_class(module, name)
raise pickle.UnpicklingError(f"Unsafe global {module}.{name}")


def load_checkpoint(model, checkpoint_path):
checkpoint = pickle.load(open(checkpoint_path, 'rb'))
checkpoint = SafeUnpickler(open(checkpoint_path, 'rb')).load()
chkp_var_dict = {var.name: var.numpy() for var in checkpoint['model']}
tf_vars = model.weights
for tf_var in tf_vars:
Expand Down
11 changes: 10 additions & 1 deletion TTS/vocoder/tf/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ def save_checkpoint(model, current_step, epoch, output_path, **kwargs):
pickle.dump(state, open(output_path, 'wb'))


class SafeUnpickler(pickle.Unpickler):
def find_class(self, module, name):
if module == "builtins" and name in {"dict", "list", "tuple", "set", "int", "float", "str", "bytes", "bool"}:
return super().find_class(module, name)
if "numpy" in module:
return super().find_class(module, name)
raise pickle.UnpicklingError(f"Unsafe global {module}.{name}")


def load_checkpoint(model, checkpoint_path):
""" Load TF Vocoder model """
checkpoint = pickle.load(open(checkpoint_path, 'rb'))
checkpoint = SafeUnpickler(open(checkpoint_path, 'rb')).load()
chkp_var_dict = {var.name: var.numpy() for var in checkpoint['model']}
tf_vars = model.weights
for tf_var in tf_vars:
Expand Down