update documentation
Browse files- README.md +44 -5
- save_model.ipynb +19 -288
- test_DAC.ipynb +7 -7
README.md
CHANGED
@@ -9,7 +9,18 @@ tags:
|
|
9 |
# Descript Audio Codec (DAC)
|
10 |
DAC is the state-of-the-art audio tokenizer with improvement upon the previous tokenizers like SoundStream and EnCodec.
|
11 |
|
12 |
-
This model card provides an easy-to-use API for a *pretrained DAC* [1] whose backbone and pretrained weights are from [its original reposotiry](https://github.com/descriptinc/descript-audio-codec). With this API, you can encode and decode by a single line of code either using CPU or GPU. Furhtermore, it supports chunk-based processing for memory-efficient processing, especially important for GPU processing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
# Usage
|
@@ -17,14 +28,42 @@ This model card provides an easy-to-use API for a *pretrained DAC* [1] whose bac
|
|
17 |
### Load
|
18 |
```python
|
19 |
from transformers import AutoModel
|
|
|
|
|
|
|
|
|
|
|
20 |
model = AutoModel.from_pretrained('hance-ai/descript-audio-codec', trust_remote_code=True)
|
|
|
21 |
```
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
|
30 |
# Runtime
|
|
|
9 |
# Descript Audio Codec (DAC)
|
10 |
DAC is the state-of-the-art audio tokenizer with improvement upon the previous tokenizers like SoundStream and EnCodec.
|
11 |
|
12 |
+
This model card provides an easy-to-use API for a *pretrained DAC* [1] for 44.1khz audio whose backbone and pretrained weights are from [its original reposotiry](https://github.com/descriptinc/descript-audio-codec). With this API, you can encode and decode by a single line of code either using CPU or GPU. Furhtermore, it supports chunk-based processing for memory-efficient processing, especially important for GPU processing.
|
13 |
+
|
14 |
+
|
15 |
+
### Model variations
|
16 |
+
There are three types of model depending on an input audio sampling rate.
|
17 |
+
|
18 |
+
| Model | Input audio sampling rate [khz] |
|
19 |
+
| ------------------ | ----------------- |
|
20 |
+
| [`hance-ai/descript-audio-codec-44khz`](https://huggingface.co/hance-ai/descript-audio-codec-24khz) | 44.1khz |
|
21 |
+
| [`hance-ai/descript-audio-codec-24khz`](https://huggingface.co/hance-ai/descript-audio-codec-24khz) | 24khz |
|
22 |
+
| [`hance-ai/descript-audio-codec-16khz`](https://huggingface.co/hance-ai/descript-audio-codec-16khz) | 16khz |
|
23 |
+
|
24 |
|
25 |
|
26 |
# Usage
|
|
|
28 |
### Load
|
29 |
```python
|
30 |
from transformers import AutoModel
|
31 |
+
|
32 |
+
# device setting
|
33 |
+
device = 'cpu' # or 'cuda:0'
|
34 |
+
|
35 |
+
# load
|
36 |
model = AutoModel.from_pretrained('hance-ai/descript-audio-codec', trust_remote_code=True)
|
37 |
+
model.to(device)
|
38 |
```
|
39 |
|
40 |
+
### Encode
|
41 |
+
```python
|
42 |
+
audio_filename = ...
|
43 |
+
zq, s = model.encode(audio_filename)
|
44 |
+
```
|
45 |
+
`zq` is discrete embeddings with dimension of (1, num_RVQ_codebooks, token_length) and `s` is a token sequence with dimension of (1, num_RVQ_codebooks, token_length).
|
46 |
|
47 |
+
|
48 |
+
### Decode
|
49 |
+
```python
|
50 |
+
# decoding from `zq`
|
51 |
+
waveform = model.decode(zq=zq) # (1, 1, audio_length); the output has a mono channel.
|
52 |
+
|
53 |
+
# decoding from `s`
|
54 |
+
waveform = model.decode(s=s) # (1, 1, audio_length); the output has a mono channel.
|
55 |
+
```
|
56 |
+
|
57 |
+
### Save a waveform as an audio file.
|
58 |
+
```python
|
59 |
+
model.waveform_to_audiofile(waveform, 'out.wav')
|
60 |
+
```
|
61 |
+
|
62 |
+
### Save and load tokens
|
63 |
+
```python
|
64 |
+
model.save_tensor(s, 'tokens.pt')
|
65 |
+
loaded_s = model.load_tensor('tokens.pt')
|
66 |
+
```
|
67 |
|
68 |
|
69 |
# Runtime
|
save_model.ipynb
CHANGED
@@ -101,302 +101,33 @@
|
|
101 |
},
|
102 |
{
|
103 |
"cell_type": "code",
|
104 |
-
"execution_count":
|
105 |
"metadata": {},
|
106 |
"outputs": [
|
107 |
{
|
108 |
-
"
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
" )\n",
|
125 |
-
" (1): ResidualUnit(\n",
|
126 |
-
" (block): Sequential(\n",
|
127 |
-
" (0): Snake1d()\n",
|
128 |
-
" (1): Conv1d(64, 64, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
129 |
-
" (2): Snake1d()\n",
|
130 |
-
" (3): Conv1d(64, 64, kernel_size=(1,), stride=(1,))\n",
|
131 |
-
" )\n",
|
132 |
-
" )\n",
|
133 |
-
" (2): ResidualUnit(\n",
|
134 |
-
" (block): Sequential(\n",
|
135 |
-
" (0): Snake1d()\n",
|
136 |
-
" (1): Conv1d(64, 64, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
137 |
-
" (2): Snake1d()\n",
|
138 |
-
" (3): Conv1d(64, 64, kernel_size=(1,), stride=(1,))\n",
|
139 |
-
" )\n",
|
140 |
-
" )\n",
|
141 |
-
" (3): Snake1d()\n",
|
142 |
-
" (4): Conv1d(64, 128, kernel_size=(4,), stride=(2,), padding=(1,))\n",
|
143 |
-
" )\n",
|
144 |
-
" )\n",
|
145 |
-
" (2): EncoderBlock(\n",
|
146 |
-
" (block): Sequential(\n",
|
147 |
-
" (0): ResidualUnit(\n",
|
148 |
-
" (block): Sequential(\n",
|
149 |
-
" (0): Snake1d()\n",
|
150 |
-
" (1): Conv1d(128, 128, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
151 |
-
" (2): Snake1d()\n",
|
152 |
-
" (3): Conv1d(128, 128, kernel_size=(1,), stride=(1,))\n",
|
153 |
-
" )\n",
|
154 |
-
" )\n",
|
155 |
-
" (1): ResidualUnit(\n",
|
156 |
-
" (block): Sequential(\n",
|
157 |
-
" (0): Snake1d()\n",
|
158 |
-
" (1): Conv1d(128, 128, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
159 |
-
" (2): Snake1d()\n",
|
160 |
-
" (3): Conv1d(128, 128, kernel_size=(1,), stride=(1,))\n",
|
161 |
-
" )\n",
|
162 |
-
" )\n",
|
163 |
-
" (2): ResidualUnit(\n",
|
164 |
-
" (block): Sequential(\n",
|
165 |
-
" (0): Snake1d()\n",
|
166 |
-
" (1): Conv1d(128, 128, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
167 |
-
" (2): Snake1d()\n",
|
168 |
-
" (3): Conv1d(128, 128, kernel_size=(1,), stride=(1,))\n",
|
169 |
-
" )\n",
|
170 |
-
" )\n",
|
171 |
-
" (3): Snake1d()\n",
|
172 |
-
" (4): Conv1d(128, 256, kernel_size=(8,), stride=(4,), padding=(2,))\n",
|
173 |
-
" )\n",
|
174 |
-
" )\n",
|
175 |
-
" (3): EncoderBlock(\n",
|
176 |
-
" (block): Sequential(\n",
|
177 |
-
" (0): ResidualUnit(\n",
|
178 |
-
" (block): Sequential(\n",
|
179 |
-
" (0): Snake1d()\n",
|
180 |
-
" (1): Conv1d(256, 256, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
181 |
-
" (2): Snake1d()\n",
|
182 |
-
" (3): Conv1d(256, 256, kernel_size=(1,), stride=(1,))\n",
|
183 |
-
" )\n",
|
184 |
-
" )\n",
|
185 |
-
" (1): ResidualUnit(\n",
|
186 |
-
" (block): Sequential(\n",
|
187 |
-
" (0): Snake1d()\n",
|
188 |
-
" (1): Conv1d(256, 256, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
189 |
-
" (2): Snake1d()\n",
|
190 |
-
" (3): Conv1d(256, 256, kernel_size=(1,), stride=(1,))\n",
|
191 |
-
" )\n",
|
192 |
-
" )\n",
|
193 |
-
" (2): ResidualUnit(\n",
|
194 |
-
" (block): Sequential(\n",
|
195 |
-
" (0): Snake1d()\n",
|
196 |
-
" (1): Conv1d(256, 256, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
197 |
-
" (2): Snake1d()\n",
|
198 |
-
" (3): Conv1d(256, 256, kernel_size=(1,), stride=(1,))\n",
|
199 |
-
" )\n",
|
200 |
-
" )\n",
|
201 |
-
" (3): Snake1d()\n",
|
202 |
-
" (4): Conv1d(256, 512, kernel_size=(16,), stride=(8,), padding=(4,))\n",
|
203 |
-
" )\n",
|
204 |
-
" )\n",
|
205 |
-
" (4): EncoderBlock(\n",
|
206 |
-
" (block): Sequential(\n",
|
207 |
-
" (0): ResidualUnit(\n",
|
208 |
-
" (block): Sequential(\n",
|
209 |
-
" (0): Snake1d()\n",
|
210 |
-
" (1): Conv1d(512, 512, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
211 |
-
" (2): Snake1d()\n",
|
212 |
-
" (3): Conv1d(512, 512, kernel_size=(1,), stride=(1,))\n",
|
213 |
-
" )\n",
|
214 |
-
" )\n",
|
215 |
-
" (1): ResidualUnit(\n",
|
216 |
-
" (block): Sequential(\n",
|
217 |
-
" (0): Snake1d()\n",
|
218 |
-
" (1): Conv1d(512, 512, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
219 |
-
" (2): Snake1d()\n",
|
220 |
-
" (3): Conv1d(512, 512, kernel_size=(1,), stride=(1,))\n",
|
221 |
-
" )\n",
|
222 |
-
" )\n",
|
223 |
-
" (2): ResidualUnit(\n",
|
224 |
-
" (block): Sequential(\n",
|
225 |
-
" (0): Snake1d()\n",
|
226 |
-
" (1): Conv1d(512, 512, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
227 |
-
" (2): Snake1d()\n",
|
228 |
-
" (3): Conv1d(512, 512, kernel_size=(1,), stride=(1,))\n",
|
229 |
-
" )\n",
|
230 |
-
" )\n",
|
231 |
-
" (3): Snake1d()\n",
|
232 |
-
" (4): Conv1d(512, 1024, kernel_size=(16,), stride=(8,), padding=(4,))\n",
|
233 |
-
" )\n",
|
234 |
-
" )\n",
|
235 |
-
" (5): Snake1d()\n",
|
236 |
-
" (6): Conv1d(1024, 1024, kernel_size=(3,), stride=(1,), padding=(1,))\n",
|
237 |
-
" )\n",
|
238 |
-
" )\n",
|
239 |
-
" (quantizer): ResidualVectorQuantize(\n",
|
240 |
-
" (quantizers): ModuleList(\n",
|
241 |
-
" (0-8): 9 x VectorQuantize(\n",
|
242 |
-
" (in_proj): Conv1d(1024, 8, kernel_size=(1,), stride=(1,))\n",
|
243 |
-
" (out_proj): Conv1d(8, 1024, kernel_size=(1,), stride=(1,))\n",
|
244 |
-
" (codebook): Embedding(1024, 8)\n",
|
245 |
-
" )\n",
|
246 |
-
" )\n",
|
247 |
-
" )\n",
|
248 |
-
" (decoder): Decoder(\n",
|
249 |
-
" (model): Sequential(\n",
|
250 |
-
" (0): Conv1d(1024, 1536, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
251 |
-
" (1): DecoderBlock(\n",
|
252 |
-
" (block): Sequential(\n",
|
253 |
-
" (0): Snake1d()\n",
|
254 |
-
" (1): ConvTranspose1d(1536, 768, kernel_size=(16,), stride=(8,), padding=(4,))\n",
|
255 |
-
" (2): ResidualUnit(\n",
|
256 |
-
" (block): Sequential(\n",
|
257 |
-
" (0): Snake1d()\n",
|
258 |
-
" (1): Conv1d(768, 768, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
259 |
-
" (2): Snake1d()\n",
|
260 |
-
" (3): Conv1d(768, 768, kernel_size=(1,), stride=(1,))\n",
|
261 |
-
" )\n",
|
262 |
-
" )\n",
|
263 |
-
" (3): ResidualUnit(\n",
|
264 |
-
" (block): Sequential(\n",
|
265 |
-
" (0): Snake1d()\n",
|
266 |
-
" (1): Conv1d(768, 768, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
267 |
-
" (2): Snake1d()\n",
|
268 |
-
" (3): Conv1d(768, 768, kernel_size=(1,), stride=(1,))\n",
|
269 |
-
" )\n",
|
270 |
-
" )\n",
|
271 |
-
" (4): ResidualUnit(\n",
|
272 |
-
" (block): Sequential(\n",
|
273 |
-
" (0): Snake1d()\n",
|
274 |
-
" (1): Conv1d(768, 768, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
275 |
-
" (2): Snake1d()\n",
|
276 |
-
" (3): Conv1d(768, 768, kernel_size=(1,), stride=(1,))\n",
|
277 |
-
" )\n",
|
278 |
-
" )\n",
|
279 |
-
" )\n",
|
280 |
-
" )\n",
|
281 |
-
" (2): DecoderBlock(\n",
|
282 |
-
" (block): Sequential(\n",
|
283 |
-
" (0): Snake1d()\n",
|
284 |
-
" (1): ConvTranspose1d(768, 384, kernel_size=(16,), stride=(8,), padding=(4,))\n",
|
285 |
-
" (2): ResidualUnit(\n",
|
286 |
-
" (block): Sequential(\n",
|
287 |
-
" (0): Snake1d()\n",
|
288 |
-
" (1): Conv1d(384, 384, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
289 |
-
" (2): Snake1d()\n",
|
290 |
-
" (3): Conv1d(384, 384, kernel_size=(1,), stride=(1,))\n",
|
291 |
-
" )\n",
|
292 |
-
" )\n",
|
293 |
-
" (3): ResidualUnit(\n",
|
294 |
-
" (block): Sequential(\n",
|
295 |
-
" (0): Snake1d()\n",
|
296 |
-
" (1): Conv1d(384, 384, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
297 |
-
" (2): Snake1d()\n",
|
298 |
-
" (3): Conv1d(384, 384, kernel_size=(1,), stride=(1,))\n",
|
299 |
-
" )\n",
|
300 |
-
" )\n",
|
301 |
-
" (4): ResidualUnit(\n",
|
302 |
-
" (block): Sequential(\n",
|
303 |
-
" (0): Snake1d()\n",
|
304 |
-
" (1): Conv1d(384, 384, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
305 |
-
" (2): Snake1d()\n",
|
306 |
-
" (3): Conv1d(384, 384, kernel_size=(1,), stride=(1,))\n",
|
307 |
-
" )\n",
|
308 |
-
" )\n",
|
309 |
-
" )\n",
|
310 |
-
" )\n",
|
311 |
-
" (3): DecoderBlock(\n",
|
312 |
-
" (block): Sequential(\n",
|
313 |
-
" (0): Snake1d()\n",
|
314 |
-
" (1): ConvTranspose1d(384, 192, kernel_size=(8,), stride=(4,), padding=(2,))\n",
|
315 |
-
" (2): ResidualUnit(\n",
|
316 |
-
" (block): Sequential(\n",
|
317 |
-
" (0): Snake1d()\n",
|
318 |
-
" (1): Conv1d(192, 192, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
319 |
-
" (2): Snake1d()\n",
|
320 |
-
" (3): Conv1d(192, 192, kernel_size=(1,), stride=(1,))\n",
|
321 |
-
" )\n",
|
322 |
-
" )\n",
|
323 |
-
" (3): ResidualUnit(\n",
|
324 |
-
" (block): Sequential(\n",
|
325 |
-
" (0): Snake1d()\n",
|
326 |
-
" (1): Conv1d(192, 192, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
327 |
-
" (2): Snake1d()\n",
|
328 |
-
" (3): Conv1d(192, 192, kernel_size=(1,), stride=(1,))\n",
|
329 |
-
" )\n",
|
330 |
-
" )\n",
|
331 |
-
" (4): ResidualUnit(\n",
|
332 |
-
" (block): Sequential(\n",
|
333 |
-
" (0): Snake1d()\n",
|
334 |
-
" (1): Conv1d(192, 192, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
335 |
-
" (2): Snake1d()\n",
|
336 |
-
" (3): Conv1d(192, 192, kernel_size=(1,), stride=(1,))\n",
|
337 |
-
" )\n",
|
338 |
-
" )\n",
|
339 |
-
" )\n",
|
340 |
-
" )\n",
|
341 |
-
" (4): DecoderBlock(\n",
|
342 |
-
" (block): Sequential(\n",
|
343 |
-
" (0): Snake1d()\n",
|
344 |
-
" (1): ConvTranspose1d(192, 96, kernel_size=(4,), stride=(2,), padding=(1,))\n",
|
345 |
-
" (2): ResidualUnit(\n",
|
346 |
-
" (block): Sequential(\n",
|
347 |
-
" (0): Snake1d()\n",
|
348 |
-
" (1): Conv1d(96, 96, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
349 |
-
" (2): Snake1d()\n",
|
350 |
-
" (3): Conv1d(96, 96, kernel_size=(1,), stride=(1,))\n",
|
351 |
-
" )\n",
|
352 |
-
" )\n",
|
353 |
-
" (3): ResidualUnit(\n",
|
354 |
-
" (block): Sequential(\n",
|
355 |
-
" (0): Snake1d()\n",
|
356 |
-
" (1): Conv1d(96, 96, kernel_size=(7,), stride=(1,), padding=(9,), dilation=(3,))\n",
|
357 |
-
" (2): Snake1d()\n",
|
358 |
-
" (3): Conv1d(96, 96, kernel_size=(1,), stride=(1,))\n",
|
359 |
-
" )\n",
|
360 |
-
" )\n",
|
361 |
-
" (4): ResidualUnit(\n",
|
362 |
-
" (block): Sequential(\n",
|
363 |
-
" (0): Snake1d()\n",
|
364 |
-
" (1): Conv1d(96, 96, kernel_size=(7,), stride=(1,), padding=(27,), dilation=(9,))\n",
|
365 |
-
" (2): Snake1d()\n",
|
366 |
-
" (3): Conv1d(96, 96, kernel_size=(1,), stride=(1,))\n",
|
367 |
-
" )\n",
|
368 |
-
" )\n",
|
369 |
-
" )\n",
|
370 |
-
" )\n",
|
371 |
-
" (5): Snake1d()\n",
|
372 |
-
" (6): Conv1d(96, 1, kernel_size=(7,), stride=(1,), padding=(3,))\n",
|
373 |
-
" (7): Tanh()\n",
|
374 |
-
" )\n",
|
375 |
-
" )\n",
|
376 |
-
" )\n",
|
377 |
-
")"
|
378 |
-
]
|
379 |
-
},
|
380 |
-
"execution_count": 7,
|
381 |
-
"metadata": {},
|
382 |
-
"output_type": "execute_result"
|
383 |
}
|
384 |
],
|
385 |
"source": [
|
386 |
"# load the uploaded model\n",
|
387 |
"from transformers import AutoModel\n",
|
388 |
-
"model = AutoModel.from_pretrained('hance-ai/descript-audio-codec', \n",
|
389 |
-
"
|
390 |
-
"model.to('cpu')"
|
391 |
-
]
|
392 |
-
},
|
393 |
-
{
|
394 |
-
"cell_type": "code",
|
395 |
-
"execution_count": null,
|
396 |
-
"metadata": {},
|
397 |
-
"outputs": [],
|
398 |
-
"source": [
|
399 |
-
"model."
|
400 |
]
|
401 |
},
|
402 |
{
|
|
|
101 |
},
|
102 |
{
|
103 |
"cell_type": "code",
|
104 |
+
"execution_count": 1,
|
105 |
"metadata": {},
|
106 |
"outputs": [
|
107 |
{
|
108 |
+
"name": "stderr",
|
109 |
+
"output_type": "stream",
|
110 |
+
"text": [
|
111 |
+
"C:\\Users\\dslee\\AppData\\Roaming\\Python\\Python38\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
112 |
+
" from .autonotebook import tqdm as notebook_tqdm\n",
|
113 |
+
"c:\\Users\\dslee\\anaconda3\\envs\\sound_effect_variation_generation\\lib\\site-packages\\huggingface_hub\\file_download.py:159: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\dslee\\.cache\\huggingface\\hub\\models--hance-ai--descript-audio-codec-44khz. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n",
|
114 |
+
"To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n",
|
115 |
+
" warnings.warn(message)\n",
|
116 |
+
"A new version of the following files was downloaded from https://huggingface.co/hance-ai/descript-audio-codec-44khz:\n",
|
117 |
+
"- model.py\n",
|
118 |
+
". Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.\n",
|
119 |
+
"C:\\Users\\dslee\\AppData\\Roaming\\Python\\Python38\\site-packages\\audiotools\\ml\\layers\\base.py:172: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n",
|
120 |
+
" model_dict = torch.load(location, \"cpu\")\n",
|
121 |
+
"c:\\Users\\dslee\\anaconda3\\envs\\sound_effect_variation_generation\\lib\\site-packages\\torch\\nn\\utils\\weight_norm.py:134: FutureWarning: `torch.nn.utils.weight_norm` is deprecated in favor of `torch.nn.utils.parametrizations.weight_norm`.\n",
|
122 |
+
" WeightNorm.apply(module, name, dim)\n"
|
123 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
}
|
125 |
],
|
126 |
"source": [
|
127 |
"# load the uploaded model\n",
|
128 |
"from transformers import AutoModel\n",
|
129 |
+
"model = AutoModel.from_pretrained('hance-ai/descript-audio-codec-44khz', trust_remote_code=True)\n",
|
130 |
+
"model.to('cpu');"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
]
|
132 |
},
|
133 |
{
|
test_DAC.ipynb
CHANGED
@@ -50,7 +50,7 @@
|
|
50 |
"source": [
|
51 |
"# load the model\n",
|
52 |
"config = DACConfig(model_type_by_sampling_freq=model_type_by_sampling_freq)\n",
|
53 |
-
"
|
54 |
]
|
55 |
},
|
56 |
{
|
@@ -69,7 +69,7 @@
|
|
69 |
],
|
70 |
"source": [
|
71 |
"# encoding\n",
|
72 |
-
"zq, s =
|
73 |
"print('zq.shape:', zq.shape)\n",
|
74 |
"print('s.shape:', s.shape)"
|
75 |
]
|
@@ -97,7 +97,7 @@
|
|
97 |
],
|
98 |
"source": [
|
99 |
"# decoding (from zq -- discrete latent vectors)\n",
|
100 |
-
"waveform =
|
101 |
"print('waveform.shape:', waveform.shape)"
|
102 |
]
|
103 |
},
|
@@ -116,7 +116,7 @@
|
|
116 |
],
|
117 |
"source": [
|
118 |
"# decoding (from s -- tokens)\n",
|
119 |
-
"waveform =
|
120 |
"print('waveform.shape:', waveform.shape)"
|
121 |
]
|
122 |
},
|
@@ -127,7 +127,7 @@
|
|
127 |
"outputs": [],
|
128 |
"source": [
|
129 |
"# save waveform into an audio file\n",
|
130 |
-
"
|
131 |
]
|
132 |
},
|
133 |
{
|
@@ -146,8 +146,8 @@
|
|
146 |
],
|
147 |
"source": [
|
148 |
"# save and load tokens\n",
|
149 |
-
"
|
150 |
-
"loaded_s =
|
151 |
]
|
152 |
},
|
153 |
{
|
|
|
50 |
"source": [
|
51 |
"# load the model\n",
|
52 |
"config = DACConfig(model_type_by_sampling_freq=model_type_by_sampling_freq)\n",
|
53 |
+
"model = DAC(config).to(device)"
|
54 |
]
|
55 |
},
|
56 |
{
|
|
|
69 |
],
|
70 |
"source": [
|
71 |
"# encoding\n",
|
72 |
+
"zq, s = model.encode(fname)\n",
|
73 |
"print('zq.shape:', zq.shape)\n",
|
74 |
"print('s.shape:', s.shape)"
|
75 |
]
|
|
|
97 |
],
|
98 |
"source": [
|
99 |
"# decoding (from zq -- discrete latent vectors)\n",
|
100 |
+
"waveform = model.decode(zq=zq)\n",
|
101 |
"print('waveform.shape:', waveform.shape)"
|
102 |
]
|
103 |
},
|
|
|
116 |
],
|
117 |
"source": [
|
118 |
"# decoding (from s -- tokens)\n",
|
119 |
+
"waveform = model.decode(s=s)\n",
|
120 |
"print('waveform.shape:', waveform.shape)"
|
121 |
]
|
122 |
},
|
|
|
127 |
"outputs": [],
|
128 |
"source": [
|
129 |
"# save waveform into an audio file\n",
|
130 |
+
"model.waveform_to_audiofile(waveform, 'out.wav')"
|
131 |
]
|
132 |
},
|
133 |
{
|
|
|
146 |
],
|
147 |
"source": [
|
148 |
"# save and load tokens\n",
|
149 |
+
"model.save_tensor(s, 'tokens.pt')\n",
|
150 |
+
"loaded_s = model.load_tensor('tokens.pt') # s == loaded_s"
|
151 |
]
|
152 |
},
|
153 |
{
|