mirror of
https://github.com/Wan-Video/Wan2.1.git
synced 2025-11-05 06:29:14 +00:00
32 lines
789 B
Python
32 lines
789 B
Python
# Adapted from https://github.com/jik876/hifi-gan under the MIT license.
|
|
# LICENSE is in incl_licenses directory.
|
|
|
|
import os
|
|
|
|
import torch
|
|
from torch.nn.utils import weight_norm
|
|
|
|
|
|
def init_weights(m, mean=0.0, std=0.01):
|
|
classname = m.__class__.__name__
|
|
if classname.find("Conv") != -1:
|
|
m.weight.data.normal_(mean, std)
|
|
|
|
|
|
def apply_weight_norm(m):
|
|
classname = m.__class__.__name__
|
|
if classname.find("Conv") != -1:
|
|
weight_norm(m)
|
|
|
|
|
|
def get_padding(kernel_size, dilation=1):
|
|
return int((kernel_size * dilation - dilation) / 2)
|
|
|
|
|
|
def load_checkpoint(filepath, device):
|
|
assert os.path.isfile(filepath)
|
|
print(f"Loading '{filepath}'")
|
|
checkpoint_dict = torch.load(filepath, map_location=device)
|
|
print("Complete.")
|
|
return checkpoint_dict
|