Upload folder using huggingface_hub
Browse files- .gitattributes +5 -0
- evaluation/QP/.ipynb_checkpoints/net-checkpoint.py +29 -0
- evaluation/QP/.ipynb_checkpoints/qp_pred-checkpoint.py +48 -0
- evaluation/QP/QP_1 +3 -0
- evaluation/QP/QP_2 +3 -0
- evaluation/QP/QP_3 +3 -0
- evaluation/QP/QP_4 +3 -0
- evaluation/QP/QP_5 +3 -0
- evaluation/QP/__pycache__/net.cpython-310.pyc +0 -0
- evaluation/QP/__pycache__/qp_pred.cpython-310.pyc +0 -0
- evaluation/QP/net.py +29 -0
- evaluation/QP/qp_pred.py +73 -0
- evaluation/QP/wav2vec_small.pt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
evaluation/QP/QP_1 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
evaluation/QP/QP_2 filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
evaluation/QP/QP_3 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
evaluation/QP/QP_4 filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
evaluation/QP/QP_5 filter=lfs diff=lfs merge=lfs -text
|
evaluation/QP/.ipynb_checkpoints/net-checkpoint.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import nn, optim
|
| 3 |
+
|
| 4 |
+
class LossPredictor(nn.Module):
|
| 5 |
+
def __init__(self, ssl_model, ssl_out_dim, dropout_rate=0.2):
|
| 6 |
+
super(LossPredictor, self).__init__()
|
| 7 |
+
self.ssl_model = ssl_model
|
| 8 |
+
self.ssl_features = ssl_out_dim
|
| 9 |
+
self.dropout = nn.Dropout(dropout_rate)
|
| 10 |
+
self.carac_interm = nn.Linear(self.ssl_features,1000) #num dim neurones
|
| 11 |
+
self.output_layer = nn.Linear(1000, 1) #1 neurones
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def forward(self, wav):
|
| 15 |
+
wav = wav.squeeze(1)
|
| 16 |
+
res = self.ssl_model(wav, mask=False, features_only=True, layer=None)
|
| 17 |
+
x = res['x']
|
| 18 |
+
if 'layer_results' in res:
|
| 19 |
+
layer_outputs = [layer[0] for layer in res['layer_results']] #12 couches
|
| 20 |
+
|
| 21 |
+
concatenated_layers = torch.cat(layer_outputs, dim=-1)
|
| 22 |
+
|
| 23 |
+
x = torch.mean(concatenated_layers, dim=0)
|
| 24 |
+
|
| 25 |
+
x = self.carac_interm(x)
|
| 26 |
+
|
| 27 |
+
x = self.dropout(x) ###Pour le MCDropout pendant train+ pred select candidate
|
| 28 |
+
x = self.output_layer(x)
|
| 29 |
+
return x.squeeze(1) #return loss
|
evaluation/QP/.ipynb_checkpoints/qp_pred-checkpoint.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def _load_sslmos_model(state):
|
| 2 |
+
"""
|
| 3 |
+
Charge le backbone fairseq + LossPredictor, puis restaure ton checkpoint finetuné.
|
| 4 |
+
Retourne (net, target_sr).
|
| 5 |
+
"""
|
| 6 |
+
device = state["device"]
|
| 7 |
+
target_sr = state.get("qp_target_sr", 24000)
|
| 8 |
+
ssl_out_dim = state.get("qp_ssl_out_dim", 9216)
|
| 9 |
+
|
| 10 |
+
base_model_ckpt = state["qp_fairseq_base_model"]
|
| 11 |
+
finetuned_ckpt = state["qp_finetuned_checkpoint"]
|
| 12 |
+
|
| 13 |
+
# --- patch torch.load (comme dans ton script) pour éviter weights_only=True par défaut ---
|
| 14 |
+
torch.serialization.add_safe_globals([__import__("argparse").Namespace])
|
| 15 |
+
original_torch_load = torch.load
|
| 16 |
+
|
| 17 |
+
def patched_torch_load(*args, **kwargs):
|
| 18 |
+
if "weights_only" not in kwargs:
|
| 19 |
+
kwargs["weights_only"] = False
|
| 20 |
+
return original_torch_load(*args, **kwargs)
|
| 21 |
+
|
| 22 |
+
torch.load = patched_torch_load
|
| 23 |
+
models, cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task([base_model_ckpt])
|
| 24 |
+
torch.load = original_torch_load
|
| 25 |
+
|
| 26 |
+
ssl_model = models[0]
|
| 27 |
+
ssl_model.remove_pretraining_modules()
|
| 28 |
+
for p in ssl_model.parameters():
|
| 29 |
+
p.requires_grad = False
|
| 30 |
+
|
| 31 |
+
net = LossPredictor(ssl_model, ssl_out_dim).to(device)
|
| 32 |
+
net.load_state_dict(torch.load(finetuned_ckpt, map_location=device))
|
| 33 |
+
net.eval()
|
| 34 |
+
|
| 35 |
+
return net, target_sr
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _load_and_resample_wav(wav_path: str, target_sr: int, device):
|
| 39 |
+
wav, sr = torchaudio.load(wav_path) # wav: [C, T]
|
| 40 |
+
# mono
|
| 41 |
+
if wav.size(0) > 1:
|
| 42 |
+
wav = wav.mean(dim=0, keepdim=True)
|
| 43 |
+
# resample
|
| 44 |
+
if sr != target_sr:
|
| 45 |
+
wav = torchaudio.functional.resample(wav, orig_freq=sr, new_freq=target_sr)
|
| 46 |
+
# shape attendue: [B, C, T] -> ici B=1
|
| 47 |
+
wav = wav.unsqueeze(0).to(device) # [1, 1, T]
|
| 48 |
+
return wav
|
evaluation/QP/QP_1
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e8b1330d505f76279ee19034f6cad43038ac973668fce9886dd2fe13cfec2254
|
| 3 |
+
size 414444305
|
evaluation/QP/QP_2
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd8994fde3a2333a2562533f8e2a3daf327736aff11fb6536ce4295b5142ec98
|
| 3 |
+
size 414444305
|
evaluation/QP/QP_3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5615e54e056e0cc7e0bb7c0e19c17dbff6dbf7605b33a6d36167095133bdbe65
|
| 3 |
+
size 414444305
|
evaluation/QP/QP_4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:349f2db578056ef776983661ae62d6f68ba14ae3c250f1913c47cb453a09f756
|
| 3 |
+
size 414444305
|
evaluation/QP/QP_5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d5e2c442b8c6511bbbde3ef69059845817ea7a14d04b0b8800b078b5f8d11e1b
|
| 3 |
+
size 414444305
|
evaluation/QP/__pycache__/net.cpython-310.pyc
ADDED
|
Binary file (1.38 kB). View file
|
|
|
evaluation/QP/__pycache__/qp_pred.cpython-310.pyc
ADDED
|
Binary file (1.71 kB). View file
|
|
|
evaluation/QP/net.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import nn, optim
|
| 3 |
+
|
| 4 |
+
class LossPredictor(nn.Module):
|
| 5 |
+
def __init__(self, ssl_model, ssl_out_dim, dropout_rate=0.2):
|
| 6 |
+
super(LossPredictor, self).__init__()
|
| 7 |
+
self.ssl_model = ssl_model
|
| 8 |
+
self.ssl_features = ssl_out_dim
|
| 9 |
+
self.dropout = nn.Dropout(dropout_rate)
|
| 10 |
+
self.carac_interm = nn.Linear(self.ssl_features,1000) #num dim neurones
|
| 11 |
+
self.output_layer = nn.Linear(1000, 1) #1 neurones
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def forward(self, wav):
|
| 15 |
+
wav = wav.squeeze(1)
|
| 16 |
+
res = self.ssl_model(wav, mask=False, features_only=True, layer=None)
|
| 17 |
+
x = res['x']
|
| 18 |
+
if 'layer_results' in res:
|
| 19 |
+
layer_outputs = [layer[0] for layer in res['layer_results']] #12 couches
|
| 20 |
+
|
| 21 |
+
concatenated_layers = torch.cat(layer_outputs, dim=-1)
|
| 22 |
+
|
| 23 |
+
x = torch.mean(concatenated_layers, dim=0)
|
| 24 |
+
|
| 25 |
+
x = self.carac_interm(x)
|
| 26 |
+
|
| 27 |
+
x = self.dropout(x) ###Pour le MCDropout pendant train+ pred select candidate
|
| 28 |
+
x = self.output_layer(x)
|
| 29 |
+
return x.squeeze(1) #return loss
|
evaluation/QP/qp_pred.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
|
| 4 |
+
def ensure_checkpoint_exists(checkpoint_path, repo_id="LIUM/TTSEval", subfolder="evaluation/QP"):
|
| 5 |
+
# Check if the file exists locally
|
| 6 |
+
if not os.path.exists(checkpoint_path):
|
| 7 |
+
print(f"File {checkpoint_path} not found. Downloading from Hugging Face...")
|
| 8 |
+
|
| 9 |
+
# This downloads the file and returns the local path to the cached version
|
| 10 |
+
# Note: checkpoint_path here should be the filename within the HF repo
|
| 11 |
+
filename = os.path.basename(checkpoint_path)
|
| 12 |
+
|
| 13 |
+
downloaded_path = hf_hub_download(
|
| 14 |
+
repo_id=repo_id,
|
| 15 |
+
filename=filename,
|
| 16 |
+
subfolder=subfolder,
|
| 17 |
+
repo_type="model"
|
| 18 |
+
)
|
| 19 |
+
return downloaded_path
|
| 20 |
+
|
| 21 |
+
return checkpoint_path
|
| 22 |
+
|
| 23 |
+
def _load_sslmos_model(state):
|
| 24 |
+
"""
|
| 25 |
+
Charge le backbone fairseq + LossPredictor, puis restaure ton checkpoint finetuné.
|
| 26 |
+
Retourne (net, target_sr).
|
| 27 |
+
"""
|
| 28 |
+
device = state["device"]
|
| 29 |
+
target_sr = state.get("qp_target_sr", 24000)
|
| 30 |
+
ssl_out_dim = state.get("qp_ssl_out_dim", 9216)
|
| 31 |
+
|
| 32 |
+
base_model_ckpt = state["qp_fairseq_base_model"]
|
| 33 |
+
finetuned_ckpt = state["qp_finetuned_checkpoint"]
|
| 34 |
+
# Update paths if necessary
|
| 35 |
+
base_model_ckpt = ensure_checkpoint_exists(base_model_ckpt)
|
| 36 |
+
finetuned_ckpt = ensure_checkpoint_exists(finetuned_ckpt)
|
| 37 |
+
|
| 38 |
+
# --- patch torch.load (comme dans ton script) pour éviter weights_only=True par défaut ---
|
| 39 |
+
torch.serialization.add_safe_globals([__import__("argparse").Namespace])
|
| 40 |
+
original_torch_load = torch.load
|
| 41 |
+
|
| 42 |
+
def patched_torch_load(*args, **kwargs):
|
| 43 |
+
if "weights_only" not in kwargs:
|
| 44 |
+
kwargs["weights_only"] = False
|
| 45 |
+
return original_torch_load(*args, **kwargs)
|
| 46 |
+
|
| 47 |
+
torch.load = patched_torch_load
|
| 48 |
+
models, cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task([base_model_ckpt])
|
| 49 |
+
torch.load = original_torch_load
|
| 50 |
+
|
| 51 |
+
ssl_model = models[0]
|
| 52 |
+
ssl_model.remove_pretraining_modules()
|
| 53 |
+
for p in ssl_model.parameters():
|
| 54 |
+
p.requires_grad = False
|
| 55 |
+
|
| 56 |
+
net = LossPredictor(ssl_model, ssl_out_dim).to(device)
|
| 57 |
+
net.load_state_dict(torch.load(finetuned_ckpt, map_location=device))
|
| 58 |
+
net.eval()
|
| 59 |
+
|
| 60 |
+
return net, target_sr
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _load_and_resample_wav(wav_path: str, target_sr: int, device):
|
| 64 |
+
wav, sr = torchaudio.load(wav_path) # wav: [C, T]
|
| 65 |
+
# mono
|
| 66 |
+
if wav.size(0) > 1:
|
| 67 |
+
wav = wav.mean(dim=0, keepdim=True)
|
| 68 |
+
# resample
|
| 69 |
+
if sr != target_sr:
|
| 70 |
+
wav = torchaudio.functional.resample(wav, orig_freq=sr, new_freq=target_sr)
|
| 71 |
+
# shape attendue: [B, C, T] -> ici B=1
|
| 72 |
+
wav = wav.unsqueeze(0).to(device) # [1, 1, T]
|
| 73 |
+
return wav
|
evaluation/QP/wav2vec_small.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c66c39eaed1b79a61ea8573f71e08f6641ff156b6a8f458cfaab53877dfa4a26
|
| 3 |
+
size 950500491
|