Upload scripts/gender_id.py with huggingface_hub
Browse files- scripts/gender_id.py +7 -9
scripts/gender_id.py
CHANGED
|
@@ -26,19 +26,17 @@ class GenderClassifier:
|
|
| 26 |
)
|
| 27 |
self.extractor = sherpa_onnx.SpeakerEmbeddingExtractor(config)
|
| 28 |
|
| 29 |
-
# config.json
|
| 30 |
-
#
|
| 31 |
-
#
|
| 32 |
-
#
|
| 33 |
-
# tracked download on the model page.
|
| 34 |
import json
|
| 35 |
|
| 36 |
head_path = hf_hub_download(HEAD_MODEL_REPO, "onnx/model.onnx")
|
| 37 |
-
|
| 38 |
-
hf_hub_download(HEAD_MODEL_REPO, "config.json")
|
| 39 |
|
| 40 |
-
with open(
|
| 41 |
-
self.label_map = json.load(f)
|
| 42 |
self.session = ort.InferenceSession(head_path, providers=["CPUExecutionProvider"])
|
| 43 |
|
| 44 |
def embed(self, samples: np.ndarray, sr: int) -> np.ndarray:
|
|
|
|
| 26 |
)
|
| 27 |
self.extractor = sherpa_onnx.SpeakerEmbeddingExtractor(config)
|
| 28 |
|
| 29 |
+
# config.json holds the output-index -> gender label mapping (as
|
| 30 |
+
# well as being one of HF Hub's default download-count query files,
|
| 31 |
+
# so loading it here also makes real use of this class register as a
|
| 32 |
+
# tracked download on the model page).
|
|
|
|
| 33 |
import json
|
| 34 |
|
| 35 |
head_path = hf_hub_download(HEAD_MODEL_REPO, "onnx/model.onnx")
|
| 36 |
+
config_path = hf_hub_download(HEAD_MODEL_REPO, "config.json")
|
|
|
|
| 37 |
|
| 38 |
+
with open(config_path, encoding="utf-8") as f:
|
| 39 |
+
self.label_map = json.load(f)["label_map"]
|
| 40 |
self.session = ort.InferenceSession(head_path, providers=["CPUExecutionProvider"])
|
| 41 |
|
| 42 |
def embed(self, samples: np.ndarray, sr: int) -> np.ndarray:
|