michsethowusu commited on
Commit
6130741
·
verified ·
1 Parent(s): 9af5e4a

Upload scripts/gender_id.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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 isn't required for inference - HF Hub's download counter
30
- # only recognizes a fixed set of filenames (config.json among them),
31
- # and gender_head.onnx/label_map.json aren't in that set, so fetching
32
- # it here is what makes each real use of this class register as a
33
- # tracked download on the model page.
34
  import json
35
 
36
  head_path = hf_hub_download(HEAD_MODEL_REPO, "onnx/model.onnx")
37
- label_map_path = hf_hub_download(HEAD_MODEL_REPO, "label_map.json")
38
- hf_hub_download(HEAD_MODEL_REPO, "config.json")
39
 
40
- with open(label_map_path, encoding="utf-8") as f:
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: