Commit
·
5161553
1
Parent(s):
4726a31
add correct usage in huggingface
Browse files
README.md
CHANGED
@@ -89,6 +89,33 @@ This project fine‑tunes a Wav2Vec2 audio classifier (e.g., `facebook/wav2vec2-
|
|
89 |
|
90 |
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. Evaluate on target devices/microphones; add noise augmentation and tune detection thresholds for deployment context.
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
## How to Get Started with the Model
|
93 |
|
94 |
Use the code below to get started with the model.
|
|
|
89 |
|
90 |
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. Evaluate on target devices/microphones; add noise augmentation and tune detection thresholds for deployment context.
|
91 |
|
92 |
+
## How to use it in HuggingFace
|
93 |
+
```bash
|
94 |
+
from transformers import AutoFeatureExtractor, AutoModelForAudioClassification, pipeline
|
95 |
+
|
96 |
+
model_id = "Amirhossein75/Keyword-Spotting"
|
97 |
+
```
|
98 |
+
# Option A — simple:
|
99 |
+
```bash
|
100 |
+
clf = pipeline("audio-classification", model=model_id)
|
101 |
+
print(clf("path/to/1sec_16kHz.wav"))
|
102 |
+
```
|
103 |
+
|
104 |
+
# Option B — manual pre/post:
|
105 |
+
```bash
|
106 |
+
fe = AutoFeatureExtractor.from_pretrained(model_id)
|
107 |
+
model = AutoModelForAudioClassification.from_pretrained(model_id)
|
108 |
+
|
109 |
+
import soundfile as sf, torch
|
110 |
+
wave, sr = sf.read("path/to/1sec_16kHz.wav")
|
111 |
+
inputs = fe(wave, sampling_rate=sr, return_tensors="pt")
|
112 |
+
with torch.no_grad():
|
113 |
+
logits = model(**inputs).logits
|
114 |
+
pred_id = int(logits.argmax(-1))
|
115 |
+
print(model.config.id2label[pred_id])
|
116 |
+
|
117 |
+
```
|
118 |
+
|
119 |
## How to Get Started with the Model
|
120 |
|
121 |
Use the code below to get started with the model.
|