-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_test.py
138 lines (120 loc) · 2.75 KB
/
data_test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 8 13:28:11 2020
@author: analoganddigital ( GitHub )
"""
import os
import numpy as np
import pandas as pd
from collections import Counter
from random import shuffle
import cv2
file_name = 'training_data.npy'
if os.path.isfile(file_name):
print("file exists , loading previous data")
training_data = list(np.load(file_name,allow_pickle=True))
'''
w=[]
a=[]
s=[]
d=[]
v=[]
j=[]
m=[]
k=[]
n_choise=[]
'''
w=[]
j=[]
m=[]
k=[]
r=[]
n_choise=[]
df = pd.DataFrame(training_data)
print(df.head())
print(Counter(df[1].apply(str)))
for data in training_data: #[img,choice] chose=[1,0,0,0,0,0]
img = data[0]
choise = data[1]
'''
if choise[0] == 1:
w.append([img,choise])
elif choise[1] == 1:
a.append([img,choise])
elif choise[2] == 1:
s.append([img,choise])
elif choise[3] == 1:
d.append([img,choise])
elif choise[4] == 1:
v.append([img,choise])
elif choise[5] == 1:
j.append([img,choise])
elif choise[6] == 1:
m.append([img,choise])
elif choise[7] == 1:
k.append([img,choise])
elif choise == [0,0,0,0,0,0,0,0]:
n_choise.append([img,choise])
'''
'''
if choise[0] == 1:
w.append([img,choise])
elif choise[1] == 1:
j.append([img,choise])
elif choise[2] == 1:
m.append([img,choise])
elif choise[3] == 1:
k.append([img,choise])
elif choise == [0,0,0,0]:
n_choise.append([img,choise])
'''
if choise[0] == 1:
w.append([img,choise])
elif choise[1] == 1:
j.append([img,choise])
elif choise[2] == 1:
m.append([img,choise])
elif choise[3] == 1:
k.append([img,choise])
elif choise[4] == 1:
r.append([img,choise])
elif choise[5] == 1:
n_choise.append([img,choise])
length=len(m)
#数据量按防御次数
'''
w=w[:length]
a=a[:length]
s=s[:length]
d=d[:length]
v=v[:length]
j=j[:length]
m=m[:length]
k=k[:length]
n_choise=n_choise[:length]
final_data = w+a+s+d+v+j+m+k+n_choise
'''
w=w[:length]
j=j[:length]
m=m[:length]
k=k[:length]
r=r[:length]
n_choise=n_choise[:length]
final_data = w+j+m+k+r+n_choise
shuffle(final_data)
print(len(final_data))
np.save('training_data_2_v2_2.npy',final_data)
'''
for data in training_data:
img = data[0]
choice = data[1]
cv2.imshow('test',img)
print(choice)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cv2.waitKey()# 视频结束后,按任意键退出
cv2.destroyAllWindows()
'''
df = pd.DataFrame(final_data)
print(df.head())
print(Counter(df[1].apply(str)))