mattricesound commited on
Commit
4c773e2
·
1 Parent(s): 8cb3861

Add max_removed_effects

Browse files
Files changed (3) hide show
  1. README.md +6 -5
  2. cfg/config.yaml +6 -1
  3. remfx/datasets.py +15 -4
README.md CHANGED
@@ -27,20 +27,21 @@
27
  - `distortion`
28
  - `reverb`
29
 
30
- ## Train CLI Options
31
  - `max_kept_effects={n}` max number of <b> Kept </b> effects to apply to each file (default: 3)
 
32
  - `model={model}` architecture to use (see 'Models')
33
  - `shuffle_kept_effects=True/False` Shuffle kept effects (default: True)
34
- - `shuffle_removed_effects=True/False` Shuffle Removed effects (default: False)
35
  - `effects_to_use={effect}` Effects to use (see 'Effects') (default: all in the list)
36
  - `effects_to_remove={effect}` Effects to remove (see 'Effects') (default: all in the list)
37
- - `trainer.accelerator='gpu'` : Use GPU (default: None)
38
- - `trainer.devices={n}` Number of GPUs to use (default: 1)
39
  - `render_files=True/False` Render files. Disable to skip rendering stage (default: True)
40
  - `render_root={path/to/dir}`. Root directory to render files to (default: DATASET_ROOT)
41
 
42
- Example: `python scripts/train.py model=demucs "effects_to_use=[distortion, reverb]" "effects_to_remove=[distortion]" "max_kept_effects=2" "shuffle_kept_effects=False" "shuffle_removed_effects=True" trainer.accelerator='gpu' trainer.devices=2`
43
 
 
44
 
45
  ## Misc.
46
  By default, files are rendered to `input_dir / processed / {string_of_effects} / {train|val|test}`.
 
27
  - `distortion`
28
  - `reverb`
29
 
30
+ ## Train Main CLI Options
31
  - `max_kept_effects={n}` max number of <b> Kept </b> effects to apply to each file (default: 3)
32
+ - `max_removed_effects={n}` max number of <b> Removed </b> effects to apply to each file (default: 4)
33
  - `model={model}` architecture to use (see 'Models')
34
  - `shuffle_kept_effects=True/False` Shuffle kept effects (default: True)
35
+ - `shuffle_removed_effects=True/False` Shuffle removed effects (default: False)
36
  - `effects_to_use={effect}` Effects to use (see 'Effects') (default: all in the list)
37
  - `effects_to_remove={effect}` Effects to remove (see 'Effects') (default: all in the list)
38
+ - `accelerator=null/gpu` Use GPU (1 device) (default: False)
 
39
  - `render_files=True/False` Render files. Disable to skip rendering stage (default: True)
40
  - `render_root={path/to/dir}`. Root directory to render files to (default: DATASET_ROOT)
41
 
42
+ Example: `python scripts/train.py model=demucs "effects_to_use=[distortion, reverb]" "effects_to_remove=[distortion]" max_kept_effects=2 max_removed_effects=4 shuffle_kept_effects=False shuffle_removed_effects=True accelerator='gpu' render_root='/home/username/datasets/vocalset'`
43
 
44
+ See `cfg/config.yaml` for more options that can be specified on the command line.
45
 
46
  ## Misc.
47
  By default, files are rendered to `input_dir / processed / {string_of_effects} / {train|val|test}`.
cfg/config.yaml CHANGED
@@ -11,8 +11,10 @@ chunk_size: 262144 # 5.5s
11
  logs_dir: "./logs"
12
  render_files: True
13
  render_root: "./data"
 
14
 
15
  max_kept_effects: 3
 
16
  shuffle_kept_effects: True
17
  shuffle_removed_effects: False
18
  effects_to_use:
@@ -52,6 +54,7 @@ datamodule:
52
  effects_to_use: ${effects_to_use}
53
  effects_to_remove: ${effects_to_remove}
54
  max_kept_effects: ${max_kept_effects}
 
55
  shuffle_kept_effects: ${shuffle_kept_effects}
56
  shuffle_removed_effects: ${shuffle_removed_effects}
57
  render_files: ${render_files}
@@ -66,6 +69,7 @@ datamodule:
66
  effects_to_use: ${effects_to_use}
67
  effects_to_remove: ${effects_to_remove}
68
  max_kept_effects: ${max_kept_effects}
 
69
  shuffle_kept_effects: ${shuffle_kept_effects}
70
  shuffle_removed_effects: ${shuffle_removed_effects}
71
  render_files: ${render_files}
@@ -80,6 +84,7 @@ datamodule:
80
  effects_to_use: ${effects_to_use}
81
  effects_to_remove: ${effects_to_remove}
82
  max_kept_effects: ${max_kept_effects}
 
83
  shuffle_kept_effects: ${shuffle_kept_effects}
84
  shuffle_removed_effects: ${shuffle_removed_effects}
85
  render_files: ${render_files}
@@ -107,7 +112,7 @@ trainer:
107
  enable_model_summary: False
108
  log_every_n_steps: 1 # Logs metrics every N batches
109
  accumulate_grad_batches: 1
110
- accelerator: null
111
  devices: 1
112
  gradient_clip_val: 10.0
113
  max_steps: 50000
 
11
  logs_dir: "./logs"
12
  render_files: True
13
  render_root: "./data"
14
+ accelerator: null
15
 
16
  max_kept_effects: 3
17
+ max_removed_effects: 4
18
  shuffle_kept_effects: True
19
  shuffle_removed_effects: False
20
  effects_to_use:
 
54
  effects_to_use: ${effects_to_use}
55
  effects_to_remove: ${effects_to_remove}
56
  max_kept_effects: ${max_kept_effects}
57
+ max_removed_effects: ${max_removed_effects}
58
  shuffle_kept_effects: ${shuffle_kept_effects}
59
  shuffle_removed_effects: ${shuffle_removed_effects}
60
  render_files: ${render_files}
 
69
  effects_to_use: ${effects_to_use}
70
  effects_to_remove: ${effects_to_remove}
71
  max_kept_effects: ${max_kept_effects}
72
+ max_removed_effects: ${max_removed_effects}
73
  shuffle_kept_effects: ${shuffle_kept_effects}
74
  shuffle_removed_effects: ${shuffle_removed_effects}
75
  render_files: ${render_files}
 
84
  effects_to_use: ${effects_to_use}
85
  effects_to_remove: ${effects_to_remove}
86
  max_kept_effects: ${max_kept_effects}
87
+ max_removed_effects: ${max_removed_effects}
88
  shuffle_kept_effects: ${shuffle_kept_effects}
89
  shuffle_removed_effects: ${shuffle_removed_effects}
90
  render_files: ${render_files}
 
112
  enable_model_summary: False
113
  log_every_n_steps: 1 # Logs metrics every N batches
114
  accumulate_grad_batches: 1
115
+ accelerator: ${accelerator}
116
  devices: 1
117
  gradient_clip_val: 10.0
118
  max_steps: 50000
remfx/datasets.py CHANGED
@@ -26,7 +26,8 @@ class VocalSet(Dataset):
26
  effect_modules: List[Dict[str, torch.nn.Module]] = None,
27
  effects_to_use: List[str] = None,
28
  effects_to_remove: List[str] = None,
29
- max_kept_effects: int = 1,
 
30
  shuffle_kept_effects: bool = True,
31
  shuffle_removed_effects: bool = False,
32
  render_files: bool = True,
@@ -44,6 +45,7 @@ class VocalSet(Dataset):
44
  mode_path = self.root / self.mode
45
  self.files = sorted(list(mode_path.glob("./**/*.wav")))
46
  self.max_kept_effects = max_kept_effects
 
47
  self.effects_to_use = effects_to_use
48
  self.effects_to_remove = effects_to_remove
49
  self.normalize = effects.LoudnessNormalize(sample_rate, target_lufs_db=-20)
@@ -130,12 +132,12 @@ class VocalSet(Dataset):
130
  )
131
  kept_fx = list(set(self.effects_to_use) - set(self.effects_to_remove))
132
  kept_str = "randomly" if self.shuffle_kept_effects else "in order"
133
- removed_str = "randomly" if self.shuffle_removed_effects else "in order"
134
  rem_fx = self.effects_to_remove
 
135
  print(
136
  f"Effect Summary: \n"
137
  f"Apply effects: {kept_fx} (Up to {self.max_kept_effects}, chosen {kept_str}) -> Dry\n"
138
- f"Apply effects: {rem_fx} (All {len(rem_fx)}, chosen {removed_str}) -> Wet\n"
139
  )
140
  return kept_fx
141
 
@@ -143,25 +145,34 @@ class VocalSet(Dataset):
143
  labels = []
144
 
145
  # Apply Kept Effects
 
146
  if self.shuffle_kept_effects:
147
  effect_indices = torch.randperm(len(self.effects_to_keep))
148
  else:
149
  effect_indices = torch.arange(len(self.effects_to_keep))
 
 
 
150
  effect_names_to_apply = [self.effects_to_keep[i] for i in effect_indices]
151
  effects_to_apply = [self.effects[i] for i in effect_names_to_apply]
 
152
  for effect in effects_to_apply:
153
  dry = effect(dry)
154
  labels.append(ALL_EFFECTS.index(type(effect)))
155
- print(labels)
156
 
157
  # Apply effects_to_remove
 
158
  wet = torch.clone(dry)
159
  if self.shuffle_removed_effects:
160
  effect_indices = torch.randperm(len(self.effects_to_remove))
161
  else:
162
  effect_indices = torch.arange(len(self.effects_to_remove))
 
 
 
163
  effect_names_to_apply = [self.effects_to_remove[i] for i in effect_indices]
164
  effects_to_apply = [self.effects[i] for i in effect_names_to_apply]
 
165
  for effect in effects_to_apply:
166
  wet = effect(wet)
167
  labels.append(ALL_EFFECTS.index(type(effect)))
 
26
  effect_modules: List[Dict[str, torch.nn.Module]] = None,
27
  effects_to_use: List[str] = None,
28
  effects_to_remove: List[str] = None,
29
+ max_kept_effects: int = 4,
30
+ max_removed_effects: int = 4,
31
  shuffle_kept_effects: bool = True,
32
  shuffle_removed_effects: bool = False,
33
  render_files: bool = True,
 
45
  mode_path = self.root / self.mode
46
  self.files = sorted(list(mode_path.glob("./**/*.wav")))
47
  self.max_kept_effects = max_kept_effects
48
+ self.max_removed_effects = max_removed_effects
49
  self.effects_to_use = effects_to_use
50
  self.effects_to_remove = effects_to_remove
51
  self.normalize = effects.LoudnessNormalize(sample_rate, target_lufs_db=-20)
 
132
  )
133
  kept_fx = list(set(self.effects_to_use) - set(self.effects_to_remove))
134
  kept_str = "randomly" if self.shuffle_kept_effects else "in order"
 
135
  rem_fx = self.effects_to_remove
136
+ rem_str = "randomly" if self.shuffle_removed_effects else "in order"
137
  print(
138
  f"Effect Summary: \n"
139
  f"Apply effects: {kept_fx} (Up to {self.max_kept_effects}, chosen {kept_str}) -> Dry\n"
140
+ f"Apply effects: {rem_fx} (Up to {self.max_removed_effects}, chosen {rem_str}) -> Wet\n"
141
  )
142
  return kept_fx
143
 
 
145
  labels = []
146
 
147
  # Apply Kept Effects
148
+ # Shuffle effects if specified
149
  if self.shuffle_kept_effects:
150
  effect_indices = torch.randperm(len(self.effects_to_keep))
151
  else:
152
  effect_indices = torch.arange(len(self.effects_to_keep))
153
+ # Up to max_kept_effects
154
+ effect_indices = effect_indices[: self.max_kept_effects]
155
+ # Index in effect settings
156
  effect_names_to_apply = [self.effects_to_keep[i] for i in effect_indices]
157
  effects_to_apply = [self.effects[i] for i in effect_names_to_apply]
158
+ # Apply
159
  for effect in effects_to_apply:
160
  dry = effect(dry)
161
  labels.append(ALL_EFFECTS.index(type(effect)))
 
162
 
163
  # Apply effects_to_remove
164
+ # Shuffle effects if specified
165
  wet = torch.clone(dry)
166
  if self.shuffle_removed_effects:
167
  effect_indices = torch.randperm(len(self.effects_to_remove))
168
  else:
169
  effect_indices = torch.arange(len(self.effects_to_remove))
170
+ # Up to max_removed_effects
171
+ effect_indices = effect_indices[: self.max_removed_effects]
172
+ # Index in effect settings
173
  effect_names_to_apply = [self.effects_to_remove[i] for i in effect_indices]
174
  effects_to_apply = [self.effects[i] for i in effect_names_to_apply]
175
+ # Apply
176
  for effect in effects_to_apply:
177
  wet = effect(wet)
178
  labels.append(ALL_EFFECTS.index(type(effect)))