-
Notifications
You must be signed in to change notification settings - Fork 7
/
FewShotPreprocessing.py
80 lines (65 loc) · 1.86 KB
/
FewShotPreprocessing.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import os.path as osp
from PIL import Image
PATH='../Fewshot/Fewshot/'
classes= os.listdir(PATH)
trainp='../Fewshot/train/'
valp='../Fewshot/val/'
testp='../Fewshot/test/'
for classv in classes:
if classv[0]=='.':
continue
pathn=osp.join(PATH,classv)
pathn=pathn+'/'
folders=os.listdir(pathn)
path1=osp.join(trainp,'images/')
path1=osp.join(path1,classv)
os.mkdir(path1)
path1 =path1 +'/'
path2=osp.join(trainp,'labels/')
path2=osp.join(path2,classv)
os.mkdir(path2)
path2=path2+'/'
for i in range(0,8,1):
p=osp.join(pathn,folders[i])
im=Image.open(p)
if(i%2==0):
p1=osp.join(path1,folders[i])
im.save(p1)
else:
p2=osp.join(path2,folders[i])
im.save(p2)
path1=osp.join(valp,'images/')
path1=osp.join(path1,classv)
os.mkdir(path1)
path1 =path1 +'/'
path2=osp.join(valp,'labels/')
path2=osp.join(path2,classv)
os.mkdir(path2)
path2=path2+'/'
for i in range(8,16,1):
p=osp.join(pathn,folders[i])
im=Image.open(p)
if(i%2==0):
p1=osp.join(path1,folders[i])
im.save(p1)
else:
p2=osp.join(path2,folders[i])
im.save(p2)
path1=osp.join(testp,'images/')
path1=osp.join(path1,classv)
os.mkdir(path1)
path1=path1+'/'
path2=osp.join(testp,'labels/')
path2=osp.join(path2,classv)
os.mkdir(path2)
path2=path2+'/'
for i in range(16,20,1):
p=osp.join(pathn,folders[i])
im=Image.open(p)
if(i%2==0):
p1=osp.join(path1,folders[i])
im.save(p1)
else:
p2=osp.join(path2,folders[i])
im.save(p2)