nii-yamagishilab commited on
Commit
abb6626
·
verified ·
1 Parent(s): 74e0d15

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -31
README.md CHANGED
@@ -63,20 +63,8 @@ conda create --name antideepfake python==3.9.0
63
  conda activate antideepfake
64
  conda install pip==24.0
65
 
66
- ### Install Fariseq ###
67
- # fairseq 0.10.2 on pip does not work
68
- git clone https://github.com/pytorch/fairseq
69
- cd fairseq
70
- # checkout this specific commit. Latest commit does not work
71
- git checkout 862efab86f649c04ea31545ce28d13c59560113d
72
- pip install --editable .
73
-
74
- ### Install other packages ###
75
- pip install huggingface-hub==0.31.1 safetensors==0.5.3 soundfile==0.13.1 numpy==1.21.2
76
- ```
77
- Additionally, you need to update line 315 in `/where/you/clone/fairseq/fairseq/checkpoint_utils.py` to:
78
- ```
79
- state = torch.load(f, map_location=torch.device("cpu"), weights_only=False)
80
  ```
81
 
82
  🚀 Inference:
@@ -85,7 +73,7 @@ import os
85
  import urllib.request
86
  import torch
87
  import torchaudio
88
- import fairseq
89
  from huggingface_hub import PyTorchModelHubMixin
90
 
91
  # This is the only part of the script you need to modify.
@@ -97,26 +85,31 @@ audio_formats = (".mp3", ".wav", ".flac", ".m4a")
97
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
98
  print(f"Using device: {device}")
99
 
100
- # === Download Fairseq checkpoint if not present ===
101
- # The downloaded checkpoint is used for building front-end architecture,
102
- # its weights will be replaced by the model.safetensors file in this repo.
103
- ssl_path = "w2v_large_lv_fsh_swbd_cv.pt"
104
- ssl_url = "https://dl.fbaipublicfiles.com/fairseq/wav2vec/w2v_large_lv_fsh_swbd_cv.pt"
105
-
106
- if not os.path.exists(ssl_path):
107
- print(f"Downloading checkpoint to {ssl_path}...")
108
- urllib.request.urlretrieve(ssl_url, ssl_path)
109
- print("Download complete.")
110
- else:
111
- print(f"{ssl_path} already exists. Skipping download.")
112
-
113
  # === Wrapper for the SSL model ===
114
  class SSLModel(torch.nn.Module):
115
  def __init__(self):
116
  super().__init__()
117
- # The downloaded .pt file is used here
118
- model, _, _ = fairseq.checkpoint_utils.load_model_ensemble_and_task([ssl_path])
119
- self.model = model[0].to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  def extract_feat(self, input_data):
122
  # If input has shape (B, T, 1), squeeze the last dim
 
63
  conda activate antideepfake
64
  conda install pip==24.0
65
 
66
+ ### Install packages ###
67
+ pip install huggingface-hub==0.31.1 fairseq==0.12.2 safetensors==0.5.3 soundfile==0.13.1
 
 
 
 
 
 
 
 
 
 
 
 
68
  ```
69
 
70
  🚀 Inference:
 
73
  import urllib.request
74
  import torch
75
  import torchaudio
76
+ from fairseq.models.wav2vec import Wav2Vec2Model, Wav2Vec2Config
77
  from huggingface_hub import PyTorchModelHubMixin
78
 
79
  # This is the only part of the script you need to modify.
 
85
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
86
  print(f"Using device: {device}")
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # === Wrapper for the SSL model ===
89
  class SSLModel(torch.nn.Module):
90
  def __init__(self):
91
  super().__init__()
92
+ # Model config used to build SSL architecture
93
+ cfg = Wav2Vec2Config(
94
+ quantize_targets=True,
95
+ extractor_mode="layer_norm",
96
+ layer_norm_first=True,
97
+ final_dim=768,
98
+ latent_temp=(2.0, 0.1, 0.999995),
99
+ encoder_layerdrop=0.0,
100
+ dropout_input=0.0,
101
+ dropout_features=0.0,
102
+ dropout=0.0,
103
+ attention_dropout=0.0,
104
+ conv_bias=True,
105
+ encoder_layers=24,
106
+ encoder_embed_dim=1024,
107
+ encoder_ffn_embed_dim=4096,
108
+ encoder_attention_heads=16,
109
+ feature_grad_mult=1.0
110
+ )
111
+ # Initialize SSL model with random weights
112
+ self.model = Wav2Vec2Model(cfg)
113
 
114
  def extract_feat(self, input_data):
115
  # If input has shape (B, T, 1), squeeze the last dim