Xenova HF staff commited on
Commit
c548018
·
verified ·
1 Parent(s): 6a22294

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -0
README.md CHANGED
@@ -6,4 +6,34 @@ base_model: pyannote/segmentation-3.0
6
 
7
  https://huggingface.co/pyannote/segmentation-3.0 with ONNX weights to be compatible with Transformers.js.
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
 
6
 
7
  https://huggingface.co/pyannote/segmentation-3.0 with ONNX weights to be compatible with Transformers.js.
8
 
9
+
10
+ ## Torch → ONNX conversion code:
11
+ ```py
12
+ # pip install torch onnx https://github.com/pyannote/pyannote-audio/archive/refs/heads/develop.zip
13
+ import torch
14
+ from pyannote.audio import Model
15
+
16
+ model = Model.from_pretrained(
17
+ "pyannote/segmentation-3.0",
18
+ use_auth_token="hf_...", # <-- Set your HF token here
19
+ ).eval()
20
+
21
+ dummy_input = torch.zeros(2, 1, 160000)
22
+ torch.onnx.export(
23
+ model,
24
+ dummy_input,
25
+ 'model.onnx',
26
+ do_constant_folding=True,
27
+ input_names=["input_features"],
28
+ output_names=["logits"],
29
+ dynamic_axes={
30
+ "input_features": {0: "batch_size", 1: "num_channels", 2: "num_samples"},
31
+ "logits": {0: "batch_size", 1: "num_frames"},
32
+ },
33
+ )
34
+ ```
35
+
36
+ ---
37
+
38
+
39
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).