-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveFiles.py
49 lines (39 loc) · 1.39 KB
/
moveFiles.py
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
import numpy as np
import os
import shutil
'''
人工打乱样本顺序,防止样本正负扎堆
'''
tmp = ['A','B','C','D']
level = 10000000
# dis_dir = 'F:/项目/花城音乐项目/参考代码/tensorflow_models_nets-master/onsets/train'
# scr_dir = 'F:/项目/花城音乐项目/参考代码/tensorflow_models_nets-master/onsets/val'
# dis_dir = 'F:/项目/花城音乐项目/参考代码/tensorflow_models_nets-master/onsets/test'
# scr_dir = 'F:/项目/花城音乐项目/参考代码/tensorflow_models_nets-master/onsets/val'
dis_dir = 'F:/项目/花城音乐项目/参考代码/tensorflow_models_nets-master/rhythm/train'
scr_dir = 'F:/项目/花城音乐项目/参考代码/tensorflow_models_nets-master/rhythm/val'
def clear_dir(sdir):
for i in tmp:
s_dir = sdir + '/' + i
shutil.rmtree(s_dir)
os.mkdir(s_dir)
for i in tmp:
d_dir = dis_dir + '/' + i
s_dir = scr_dir + '/' + i
total = len(os.listdir(d_dir))
if total < level:
level = total
print(level)
level = int(level*0.85)
print(level)
#清空文件夹
clear_dir(scr_dir)
for i in tmp:
d_dir = dis_dir + '/' + i
s_dir = scr_dir + '/' + i
total = len(os.listdir(d_dir))
while total > level:
files = os.listdir(d_dir)
index = np.random.randint(total)
shutil.move(d_dir + '/' + files[index], s_dir + '/' + files[index])
total = len(os.listdir(d_dir))