Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(utils): better implementation of repeat_expand_2d #216

Merged
merged 1 commit into from
Apr 3, 2023
Merged
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
18 changes: 6 additions & 12 deletions src/so_vits_svc_fork/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,12 @@ def get_hparams(config_path: Path | str) -> HParams:
def repeat_expand_2d(content: torch.Tensor, target_len: int) -> torch.Tensor:
# content : [h, t]
src_len = content.shape[-1]
target = torch.zeros(
[content.shape[0], target_len], dtype=content.dtype, device=content.device
)
temp = torch.arange(src_len + 1) * target_len / src_len
current_pos = 0
for i in range(target_len):
if i < temp[current_pos + 1]:
target[:, i] = content[:, current_pos]
else:
current_pos += 1
target[:, i] = content[:, current_pos]
return target
if target_len < src_len:
return content[:, :target_len]
else:
return torch.nn.functional.interpolate(
content.unsqueeze(0), size=target_len, mode="nearest"
).squeeze(0)


def plot_data_to_numpy(x: ndarray, y: ndarray) -> ndarray:
Expand Down