File size: 2,701 Bytes
d16e9f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import datasets
import os
import shutil
#from datasets import load_dataset
train0, validation0, test0  = datasets.load_dataset("superb", "ks", split=["train","validation","test"])

labels = train0.features["label"].names
label2id = {x: labels.index(x) for x in labels}
# id2label = {str(id): label for label, id in label2id.items()}

down_id = label2id['down']
on_id = label2id['on']

train0_down = train0.filter(lambda example: example['label'] == down_id)
train0_on = train0.filter(lambda example: example['label'] == on_id)

shutil.rmtree('/home/mr249/ac_h/down_on/data/train/down',ignore_errors=True)
os.mkdir('/home/mr249/ac_h/down_on/data/train/down')
shutil.rmtree('/home/mr249/ac_h/down_on/data/train/on',ignore_errors=True)
os.mkdir('/home/mr249/ac_h/down_on/data/train/on')

for e in train0_down:
    p = e['audio']['path']
    newpath =  '/home/mr249/ac_h/down_on/data/train/down/{}'.format(p.split('/')[len(p.split('/')) - 1])
    os.link(p,newpath)

for e in train0_on:
    p = e['audio']['path']
    newpath =  '/home/mr249/ac_h/down_on/data/train/on/{}'.format(p.split('/')[len(p.split('/')) - 1])
    os.link(p,newpath)    

validation0_down = validation0.filter(lambda example: example['label'] == down_id)
validation0_on = validation0.filter(lambda example: example['label'] == on_id)

shutil.rmtree('/home/mr249/ac_h/down_on/data/validation/down',ignore_errors=True)
os.mkdir('/home/mr249/ac_h/down_on/data/validation/down')
shutil.rmtree('/home/mr249/ac_h/down_on/data/validation/on',ignore_errors=True)
os.mkdir('/home/mr249/ac_h/down_on/data/validation/on')

for e in validation0_down:
    p = e['audio']['path']
    newpath =  '/home/mr249/ac_h/down_on/data/validation/down/{}'.format(p.split('/')[len(p.split('/')) - 1])
    os.link(p,newpath)

for e in validation0_on:
    p = e['audio']['path']
    newpath =  '/home/mr249/ac_h/down_on/data/validation/on/{}'.format(p.split('/')[len(p.split('/')) - 1])
    os.link(p,newpath)    

test0_down = test0.filter(lambda example: example['label'] == down_id)
test0_on = test0.filter(lambda example: example['label'] == on_id)

shutil.rmtree('/home/mr249/ac_h/down_on/data/test/down',ignore_errors=True)
os.mkdir('/home/mr249/ac_h/down_on/data/test/down')
shutil.rmtree('/home/mr249/ac_h/down_on/data/test/on',ignore_errors=True)
os.mkdir('/home/mr249/ac_h/down_on/data/test/on')

for e in test0_down:
    p = e['audio']['path']
    newpath =  '/home/mr249/ac_h/down_on/data/test/down/{}'.format(p.split('/')[len(p.split('/')) - 1])
    os.link(p,newpath)

for e in test0_on:
    p = e['audio']['path']
    newpath =  '/home/mr249/ac_h/down_on/data/test/on/{}'.format(p.split('/')[len(p.split('/')) - 1])
    os.link(p,newpath)