質問編集履歴

1

コードを追加

2020/12/06 02:38

投稿

shosin__
shosin__

スコア6

test CHANGED
File without changes
test CHANGED
@@ -17,3 +17,183 @@
17
17
  File "<string>", line 52, in <module>
18
18
 
19
19
  ValueError: object not in sequence
20
+
21
+
22
+
23
+ コード
24
+
25
+
26
+
27
+ import image
28
+
29
+ import lcd
30
+
31
+ import sensor
32
+
33
+ import sys
34
+
35
+ import time
36
+
37
+ import KPU as kpu
38
+
39
+ from fpioa_manager import *
40
+
41
+
42
+
43
+ import KPU as kpu
44
+
45
+
46
+
47
+
48
+
49
+ lcd.init()
50
+
51
+ lcd.rotation(2)
52
+
53
+
54
+
55
+ try:
56
+
57
+ from pmu import axp192
58
+
59
+ pmu = axp192()
60
+
61
+ pmu.enablePMICSleepMode(True)
62
+
63
+ except:
64
+
65
+ pass
66
+
67
+
68
+
69
+ try:
70
+
71
+ img = image.Image("/sd/startup.jpg")
72
+
73
+ lcd.display(img)
74
+
75
+ except:
76
+
77
+ lcd.draw_string(lcd.width()//2-100,lcd.height()//2-4, "Error: Cannot find start.jpg", lcd.WHITE, lcd.RED)
78
+
79
+
80
+
81
+
82
+
83
+ task = kpu.load("/sd/270da14b7e06e658_mbnet10_quant.kmodel")
84
+
85
+
86
+
87
+ labels=["kami","kan1","kan2","pet1","pet2"] #You can check the numbers here to real names.
88
+
89
+
90
+
91
+ sensor.reset()
92
+
93
+ sensor.set_pixformat(sensor.RGB565)
94
+
95
+ sensor.set_framesize(sensor.QVGA)
96
+
97
+ sensor.set_windowing((224, 224))
98
+
99
+ sensor.run(1)
100
+
101
+
102
+
103
+ lcd.clear()
104
+
105
+
106
+
107
+ detection_a = 0
108
+
109
+ detection_b = 0
110
+
111
+ detection_c = 0
112
+
113
+ detection_d = 0
114
+
115
+ detection_e = 0
116
+
117
+
118
+
119
+ while(True):
120
+
121
+ img = sensor.snapshot()
122
+
123
+ fmap = kpu.forward(task, img)
124
+
125
+ plist=fmap[:]
126
+
127
+ pmax=max(plist)
128
+
129
+ max_index=plist.index(pmax)
130
+
131
+ a = lcd.display(img)
132
+
133
+
134
+
135
+ max_label = ""
136
+
137
+ if pmax > 0.95:
138
+
139
+ max_label = labels[max_index]
140
+
141
+ #lcd.draw_string(40, 60, "Accu:%.2f Type:%s"%(pmax, max_label))
142
+
143
+ if max_label == 'kami' :
144
+
145
+ detection_a += 1
146
+
147
+ elif max_label == 'kan1':
148
+
149
+ detection_b += 1
150
+
151
+ elif max_label == 'kan2' :
152
+
153
+ detection_c += 1
154
+
155
+ elif max_label == 'pet1' :
156
+
157
+ detection_d += 1
158
+
159
+ elif max_label == 'pet2' :
160
+
161
+ detection_e += 1
162
+
163
+
164
+
165
+ if detection_a == 20 or detection_b == 20 or detection_c == 20 or detection_d == 20 or detection_e == 20:
166
+
167
+ print(labels[max_index])
168
+
169
+ lcd.draw_string(40, 60, "Accu:%.2f Type:%s"%(pmax, max_label))
170
+
171
+
172
+
173
+ detection_a = 0
174
+
175
+ detection_b = 0
176
+
177
+ detection_c = 0
178
+
179
+ detection_d = 0
180
+
181
+ detection_e = 0
182
+
183
+
184
+
185
+ sensor.reset()
186
+
187
+ sensor.set_pixformat(sensor.RGB565)
188
+
189
+ sensor.set_framesize(sensor.QVGA)
190
+
191
+ sensor.set_windowing((224, 224))
192
+
193
+ sensor.run(1)
194
+
195
+
196
+
197
+ lcd.clear()
198
+
199
+ a = kpu.deinit(task)