danjacobellis commited on
Commit
37e54ee
·
1 Parent(s): 3961dcf

Upload upload.ipynb

Browse files
Files changed (1) hide show
  1. upload.ipynb +216 -0
upload.ipynb ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 6,
6
+ "id": "b13595e3-ccbe-452d-b1da-056316b377a9",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import musdb\n",
11
+ "import datasets\n",
12
+ "import torch\n",
13
+ "import torchaudio\n",
14
+ "import tempfile"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 7,
20
+ "id": "f94aecdc-640d-4a0d-b16e-bf0f07637d80",
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "components = [\n",
25
+ " 'mixture',\n",
26
+ " 'drums',\n",
27
+ " 'bass',\n",
28
+ " 'other',\n",
29
+ " 'vocals'\n",
30
+ "]\n",
31
+ "fs = 44100\n",
32
+ "features=datasets.Features(\n",
33
+ " {\n",
34
+ " \"name\": datasets.Value(\"string\"),\n",
35
+ " **{\n",
36
+ " comp: datasets.Audio(\n",
37
+ " sampling_rate=fs, mono=False\n",
38
+ " )\n",
39
+ " for comp in components\n",
40
+ " }\n",
41
+ " }\n",
42
+ ") "
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 8,
48
+ "id": "1dbac3bd-0ec3-4b0f-8f46-2659ebff0049",
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "mus_test = musdb.DB(\n",
53
+ " root=\"musdb18hq\",\n",
54
+ " subsets = \"test\",\n",
55
+ " is_wav = True,\n",
56
+ " download=False\n",
57
+ ") "
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": 9,
63
+ "id": "eaeb97d6-b381-48a9-87f7-a1a5127ed05b",
64
+ "metadata": {},
65
+ "outputs": [],
66
+ "source": [
67
+ "def encode(audio):\n",
68
+ " audio = torch.tensor(audio).to(torch.float32).permute((1,0))\n",
69
+ " with tempfile.NamedTemporaryFile() as f:\n",
70
+ " torchaudio.save(f.name, audio, sample_rate=fs, format=\"wav\")\n",
71
+ " bytes = f.file.read(-1)\n",
72
+ " encoded = datasets.Audio(\n",
73
+ " sampling_rate=fs,\n",
74
+ " mono=False,\n",
75
+ " decode=False\n",
76
+ " ).encode_example(value={\"path\" : None, \"bytes\": bytes})\n",
77
+ " return encoded"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "id": "d59e2e48-5b97-4941-80e0-83630d647447",
84
+ "metadata": {},
85
+ "outputs": [
86
+ {
87
+ "name": "stdout",
88
+ "output_type": "stream",
89
+ "text": [
90
+ "0\n",
91
+ "1\n",
92
+ "2\n",
93
+ "3\n",
94
+ "4\n",
95
+ "5\n",
96
+ "6\n",
97
+ "7\n",
98
+ "8\n",
99
+ "9\n",
100
+ "10\n",
101
+ "11\n",
102
+ "12\n",
103
+ "13\n",
104
+ "14\n"
105
+ ]
106
+ },
107
+ {
108
+ "data": {
109
+ "application/vnd.jupyter.widget-view+json": {
110
+ "model_id": "ab1203173acb42f2b02dc7647361ea27",
111
+ "version_major": 2,
112
+ "version_minor": 0
113
+ },
114
+ "text/plain": [
115
+ "Map: 0%| | 0/2 [00:00<?, ? examples/s]"
116
+ ]
117
+ },
118
+ "metadata": {},
119
+ "output_type": "display_data"
120
+ },
121
+ {
122
+ "data": {
123
+ "application/vnd.jupyter.widget-view+json": {
124
+ "model_id": "e947a6f2024b457cbe06781e9cc4436b",
125
+ "version_major": 2,
126
+ "version_minor": 0
127
+ },
128
+ "text/plain": [
129
+ "Pushing dataset shards to the dataset hub: 0%| | 0/14 [00:00<?, ?it/s]"
130
+ ]
131
+ },
132
+ "metadata": {},
133
+ "output_type": "display_data"
134
+ },
135
+ {
136
+ "data": {
137
+ "application/vnd.jupyter.widget-view+json": {
138
+ "model_id": "a61a2b49619448dfa51f2e743e482160",
139
+ "version_major": 2,
140
+ "version_minor": 0
141
+ },
142
+ "text/plain": [
143
+ "Creating parquet from Arrow format: 0%| | 0/1 [00:00<?, ?ba/s]"
144
+ ]
145
+ },
146
+ "metadata": {},
147
+ "output_type": "display_data"
148
+ },
149
+ {
150
+ "data": {
151
+ "application/vnd.jupyter.widget-view+json": {
152
+ "model_id": "4f5c9fa126f94f1b9b6256956d40bd80",
153
+ "version_major": 2,
154
+ "version_minor": 0
155
+ },
156
+ "text/plain": [
157
+ "Upload 1 LFS files: 0%| | 0/1 [00:00<?, ?it/s]"
158
+ ]
159
+ },
160
+ "metadata": {},
161
+ "output_type": "display_data"
162
+ }
163
+ ],
164
+ "source": [
165
+ "%%time\n",
166
+ "name = []\n",
167
+ "mixture = []\n",
168
+ "drums = []\n",
169
+ "bass = []\n",
170
+ "other = []\n",
171
+ "vocals = []\n",
172
+ "for i_track,track in enumerate(mus_test[0:15]):\n",
173
+ " print(i_track)\n",
174
+ " name.append(track.name)\n",
175
+ " mixture.append(encode(track.audio))\n",
176
+ " drums.append(encode(track.targets['drums'].audio))\n",
177
+ " bass.append(encode(track.targets['bass'].audio))\n",
178
+ " other.append(encode(track.targets['other'].audio))\n",
179
+ " vocals.append(encode(track.targets['vocals'].audio)) \n",
180
+ "dataset = datasets.Dataset.from_dict(\n",
181
+ " {\n",
182
+ " 'name': name,\n",
183
+ " 'mixture': mixture,\n",
184
+ " 'drums': drums,\n",
185
+ " 'bass': bass,\n",
186
+ " 'other': other,\n",
187
+ " 'vocals': vocals \n",
188
+ " },\n",
189
+ " features=features\n",
190
+ ")\n",
191
+ "dataset.push_to_hub(\"danjacobellis/musdb\", split='test')"
192
+ ]
193
+ }
194
+ ],
195
+ "metadata": {
196
+ "kernelspec": {
197
+ "display_name": "Python 3 (ipykernel)",
198
+ "language": "python",
199
+ "name": "python3"
200
+ },
201
+ "language_info": {
202
+ "codemirror_mode": {
203
+ "name": "ipython",
204
+ "version": 3
205
+ },
206
+ "file_extension": ".py",
207
+ "mimetype": "text/x-python",
208
+ "name": "python",
209
+ "nbconvert_exporter": "python",
210
+ "pygments_lexer": "ipython3",
211
+ "version": "3.10.12"
212
+ }
213
+ },
214
+ "nbformat": 4,
215
+ "nbformat_minor": 5
216
+ }