Spaces:
Running
Running
Update neural_acoustic_distance.py
Browse files- neural_acoustic_distance.py +11 -9
neural_acoustic_distance.py
CHANGED
|
@@ -54,6 +54,13 @@ def load_wav2vec2_featurizer(model_id: str, layer: Optional[int] = None):
|
|
| 54 |
model.cuda()
|
| 55 |
# st.success("Done!")
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
@torch.no_grad()
|
| 58 |
def _featurize(path):
|
| 59 |
input_values, rate = sf.read(path, dtype=np.float32)
|
|
@@ -83,16 +90,9 @@ def load_wav2vec2_featurizer(model_id: str, layer: Optional[int] = None):
|
|
| 83 |
|
| 84 |
return hidden_state
|
| 85 |
|
| 86 |
-
return _featurize
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
#@st.cache(persist=True, show_spinner=False, max_entries=3)
|
| 90 |
-
def run(model_id, layer, filename_x, filename_y):
|
| 91 |
-
featurizer = load_wav2vec2_featurizer(model_id, layer)
|
| 92 |
-
|
| 93 |
with st.spinner("Measuring distance..."):
|
| 94 |
-
feats_x =
|
| 95 |
-
feats_y =
|
| 96 |
print('3. Features computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
| 97 |
gcm = aligner(feats_x, feats_y)
|
| 98 |
print('4. Alignments computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
|
@@ -102,6 +102,8 @@ def run(model_id, layer, filename_x, filename_y):
|
|
| 102 |
|
| 103 |
c, n = compute_costs(gcm)
|
| 104 |
print('5. Costs computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
|
|
|
|
|
|
| 105 |
return d, c, n
|
| 106 |
|
| 107 |
|
|
|
|
| 54 |
model.cuda()
|
| 55 |
# st.success("Done!")
|
| 56 |
|
| 57 |
+
return model
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
#@st.cache(persist=True, show_spinner=False, max_entries=3)
|
| 61 |
+
def run(model_id, layer, filename_x, filename_y):
|
| 62 |
+
model = load_wav2vec2_featurizer(model_id, layer)
|
| 63 |
+
|
| 64 |
@torch.no_grad()
|
| 65 |
def _featurize(path):
|
| 66 |
input_values, rate = sf.read(path, dtype=np.float32)
|
|
|
|
| 90 |
|
| 91 |
return hidden_state
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
with st.spinner("Measuring distance..."):
|
| 94 |
+
feats_x = _featurize(filename_x)
|
| 95 |
+
feats_y = _featurize(filename_y)
|
| 96 |
print('3. Features computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
| 97 |
gcm = aligner(feats_x, feats_y)
|
| 98 |
print('4. Alignments computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
|
|
|
| 102 |
|
| 103 |
c, n = compute_costs(gcm)
|
| 104 |
print('5. Costs computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
| 105 |
+
|
| 106 |
+
del model
|
| 107 |
return d, c, n
|
| 108 |
|
| 109 |
|