Repository: voicepaw/so-vits-svc-fork

Issue:
Pre-resample not running?
Trying to run `svc pre-resample` but it doesn't start:

`(venv) C:\Users\LXC PC\Desktop\sovits\venv\Scripts>svc pre-resample`
`Preprocessing: 0it [00:00, ?it/s]`


Discussion:
https://github.com/34j/so-vits-svc-fork/blob/main/src/so_vits_svc_fork/__main__.py#L374-L374


This part contradicts the documentation...
I managed to get it working by manually specifying the path: `svc pre-resample -i "C:\Users\LXC PC\Desktop\sovits\venv\Scripts\dataset_raw\44k\21Raw"`

Ran through `svc pre-config` and `svc pre-hubert` with no problems.

However, when running `svc train`, I get an error. Here is the stack trace:

```
(venv) C:\Users\LXC PC\Desktop\sovits\venv\Scripts>svc train
'emb_g.weight'
Traceback (most recent call last):
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\utils.py", line 385, in load_checkpoint
    new_state_dict[k] = saved_state_dict[k]
KeyError: 'emb_g.weight'
emb_g.weight is not in the checkpoint
  0%|                                                                                        | 0/10000 [00:00<?, ?it/s]C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\functional.py:641: UserWarning: stft with return_complex=False is deprecated. In a future pytorch release, stft will return complex tensors for all inputs, and return_complex=False will raise an error.
Note: you can still call torch.view_as_real on the complex output to recover the old return format. (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\SpectralOps.cpp:867.)
  return _VF.stft(input, n_fft, hop_length, win_length, window,  # type: ignore[attr-defined]
C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\autograd\__init__.py:200: UserWarning: Grad strides do not match bucket view strides. This may indicate grad was not created according to the gradient layout contract, or that the param's strides changed since DDP was constructed.  This is not an error, but may impair performance.
grad.sizes() = [32, 1, 4], strides() = [4, 1, 1]
bucket_view.sizes() = [32, 1, 4], strides() = [4, 4, 1] (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\torch\csrc\distributed\c10d\reducer.cpp:337.)
  Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  0%|                                                                                        | 0/10000 [00:13<?, ?it/s]
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\LXC PC\Desktop\sovits\venv\Scripts\svc.exe\__main__.py", line 7, in <module>
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\__main__.py", line 119, in train
    train(config_path=config_path, model_path=model_path)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\train.py", line 49, in train
    mp.spawn(
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\multiprocessing\spawn.py", line 239, in spawn
    return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\multiprocessing\spawn.py", line 197, in start_processes
    while not context.join():
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\multiprocessing\spawn.py", line 160, in join
    raise ProcessRaisedException(msg, error_index, failed_process.pid)
torch.multiprocessing.spawn.ProcessRaisedException:

-- Process 0 terminated with the following error:
Traceback (most recent call last):
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\multiprocessing\spawn.py", line 69, in _wrap
    fn(i, *args)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\train.py", line 158, in run
    train_and_evaluate(
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\train.py", line 338, in train_and_evaluate
    evaluate(hps, net_g, eval_loader, writer_eval)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\train.py", line 376, in evaluate
    for batch_idx, items in enumerate(eval_loader):
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\utils\data\dataloader.py", line 634, in __next__
    data = self._next_data()
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\utils\data\dataloader.py", line 1346, in _next_data
    return self._process_data(data)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\utils\data\dataloader.py", line 1372, in _process_data
    data.reraise()
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\_utils.py", line 644, in reraise
    raise exception
AssertionError: Caught AssertionError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\utils\data\_utils\worker.py", line 308, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 51, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\torch\utils\data\_utils\fetch.py", line 51, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\data_utils.py", line 104, in __getitem__
    return self.get_audio(self.audiopaths[index][0])
  File "C:\Users\LXC PC\Desktop\sovits\venv\lib\site-packages\so_vits_svc_fork\data_utils.py", line 78, in get_audio
    assert abs(c.size(-1) - spec.size(-1)) < 3, (
AssertionError: (1398, 1392, torch.Size([1398]), 'dataset/44k/21Raw/101.wav')
```
Was the logs/44k empty from the beginning?
logs/44k contains these files:

![01](https://user-images.githubusercontent.com/125531852/226294228-4d5cbd10-f778-4b09-b12c-1d6d1a29ab28.png)

Was it empty at first?
You mean before doing `svc train`? I think so, yea. It only created the `logs` folder after running the command. The folder didnt exist before then.
This is due to the fact that I migrated the library for f0 inference from dio to crepe without adequate testing. Please use version <0.8.0. Sorry for your inconvenience.

Resolving patch:
diff --git a/src/so_vits_svc_fork/__main__.py b/src/so_vits_svc_fork/__main__.py
--- a/src/so_vits_svc_fork/__main__.py
+++ b/src/so_vits_svc_fork/__main__.py
@@ -371,7 +371,7 @@ def vc(
     "-i",
     "--input-dir",
     type=click.Path(exists=True),
-    default=Path("./dataset_raw/44k"),
+    default=Path("./dataset_raw"),
     help="path to source dir",
 )
 @click.option(
diff --git a/src/so_vits_svc_fork/preprocess_resample.py b/src/so_vits_svc_fork/preprocess_resample.py
--- a/src/so_vits_svc_fork/preprocess_resample.py
+++ b/src/so_vits_svc_fork/preprocess_resample.py
@@ -1,5 +1,6 @@
 from __future__ import annotations
 
+import warnings
 from logging import getLogger
 from pathlib import Path
 from typing import Iterable
@@ -35,6 +36,17 @@ def _get_unique_filename(path: Path, existing_paths: Iterable[Path]) -> Path:
         i += 1
 
 
+def is_relative_to(path: Path, *other):
+    """Return True if the path is relative to another path or False.
+    Python 3.9+ has Path.is_relative_to() method, but we need to support Python 3.8.
+    """
+    try:
+        path.relative_to(*other)
+        return True
+    except ValueError:
+        return False
+
+
 def preprocess_resample(
     input_dir: Path | str, output_dir: Path | str, sampling_rate: int
 ) -> None:
@@ -71,6 +83,17 @@ def preprocess_one(input_path: Path, output_path: Path) -> None:
     out_paths = []
     for in_path in input_dir.rglob("*.*"):
         in_path_relative = in_path.relative_to(input_dir)
+        if not in_path.is_absolute() and is_relative_to(
+            in_path, Path("dataset_raw") / "44k"
+        ):
+            new_in_path_relative = in_path_relative.relative_to("44k")
+            warnings.warn(
+                f"Recommended folder structure has changed since v1.0.0. "
+                "Please move your dataset directly under dataset_raw folder. "
+                f"Recoginzed {in_path_relative} as {new_in_path_relative}"
+            )
+            in_path_relative = new_in_path_relative
+
         if len(in_path_relative.parts) < 2:
             continue
         speaker_name = in_path_relative.parts[0]


Test patch:
diff --git a/tests/dataset_raw/44k/34j/1.wav b/tests/dataset_raw/34j/nested/1.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/1.wav
rename to tests/dataset_raw/34j/nested/1.wav
diff --git a/tests/dataset_raw/44k/34j/nested/10.wav b/tests/dataset_raw/34j/nested/10.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/10.wav
rename to tests/dataset_raw/34j/nested/10.wav
diff --git a/tests/dataset_raw/44k/34j/nested/2.wav b/tests/dataset_raw/34j/nested/2.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/2.wav
rename to tests/dataset_raw/34j/nested/2.wav
diff --git a/tests/dataset_raw/44k/34j/nested/3.wav b/tests/dataset_raw/34j/nested/3.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/3.wav
rename to tests/dataset_raw/34j/nested/3.wav
diff --git a/tests/dataset_raw/44k/34j/nested/4.wav b/tests/dataset_raw/34j/nested/4.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/4.wav
rename to tests/dataset_raw/34j/nested/4.wav
diff --git a/tests/dataset_raw/44k/34j/nested/5.wav b/tests/dataset_raw/34j/nested/5.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/5.wav
rename to tests/dataset_raw/34j/nested/5.wav
diff --git a/tests/dataset_raw/44k/34j/nested/6.wav b/tests/dataset_raw/34j/nested/6.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/6.wav
rename to tests/dataset_raw/34j/nested/6.wav
diff --git a/tests/dataset_raw/44k/34j/nested/7.wav b/tests/dataset_raw/34j/nested/7.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/7.wav
rename to tests/dataset_raw/34j/nested/7.wav
diff --git a/tests/dataset_raw/44k/34j/nested/8.wav b/tests/dataset_raw/34j/nested/8.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/8.wav
rename to tests/dataset_raw/34j/nested/8.wav
diff --git a/tests/dataset_raw/44k/34j/nested/9.wav b/tests/dataset_raw/34j/nested/9.wav
similarity index 100%
rename from tests/dataset_raw/44k/34j/nested/9.wav
rename to tests/dataset_raw/34j/nested/9.wav
diff --git a/tests/dataset_raw/44k/34j/11.wav b/tests/dataset_raw/44k/34j/11.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/11.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/12.wav b/tests/dataset_raw/44k/34j/12.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/12.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/13.wav b/tests/dataset_raw/44k/34j/13.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/13.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/14.wav b/tests/dataset_raw/44k/34j/14.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/14.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/15.wav b/tests/dataset_raw/44k/34j/15.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/15.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/16.wav b/tests/dataset_raw/44k/34j/16.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/16.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/17.wav b/tests/dataset_raw/44k/34j/17.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/17.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/18.wav b/tests/dataset_raw/44k/34j/18.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/18.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/19.wav b/tests/dataset_raw/44k/34j/19.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/19.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/20.wav b/tests/dataset_raw/44k/34j/20.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/20.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/nested/1.wav b/tests/dataset_raw/44k/34j/nested/1.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/nested/1.wav and /dev/null differ
diff --git a/tests/dataset_raw/44k/34j/nested2/1.wav b/tests/dataset_raw/44k/34j/nested2/1.wav
deleted file mode 100644
Binary files a/tests/dataset_raw/44k/34j/nested2/1.wav and /dev/null differ
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -22,14 +22,13 @@ def test_infer(self):
             raise SkipTest("Skip inference test on CI")
         from so_vits_svc_fork.inference_main import infer  # noqa
 
-        # infer("tests/dataset_raw/44k/34j/1.wav", "tests/configs/config.json", "tests/logs/44k")
+        # infer("tests/dataset_raw/34j/1.wav", "tests/configs/config.json", "tests/logs/44k")
 
     def test_preprocess(self):
         from so_vits_svc_fork.preprocess_resample import preprocess_resample
 
-        preprocess_resample("tests/dataset_raw/44k", "tests/dataset/44k", 44100)
+        preprocess_resample("tests/dataset_raw", "tests/dataset/44k", 44100)
 
-    def test_preprocess_config(self):
         from so_vits_svc_fork.preprocess_flist_config import preprocess_config
 
         preprocess_config(
@@ -40,9 +39,8 @@ def test_preprocess_config(self):
             "tests/configs/config.json",
         )
 
-    def test_preprocess_hubert(self):
         if IS_CI:
-            raise SkipTest("Skip preprocessing test on CI")
+            raise SkipTest("Skip hubert and f0 test on CI")
         from so_vits_svc_fork.preprocess_hubert_f0 import preprocess_hubert_f0
 
         preprocess_hubert_f0("tests/dataset/44k", "tests/configs/44k/config.json")