Skip to content

Commit 3e117e9

Browse files
committed
Update model (add pooling layer to reduce size of last 7x7x512=25088 layer down to 3x3x512=4608 before final dense layers.
1 parent e562246 commit 3e117e9

File tree

2 files changed

+355
-315
lines changed

2 files changed

+355
-315
lines changed

Diff for: app/asl_detect_live.py

+44-10
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def detect_dpu_architecture():
9292
print("camera",input_video," (",frame_width,",",frame_height,")")
9393

9494
# Open ASL model
95-
#model = load_model('tf2_asl_classifier.h5')
95+
#model = load_model('tf2_asl_classifier_1.h5')
9696

9797
# Vitis-AI implementation of ASL model
9898

@@ -161,7 +161,7 @@ def TopK(datain, size, filePath):
161161
dpu_arch = detect_dpu_architecture()
162162
print('[INFO] Detected DPU architecture : ',dpu_arch)
163163

164-
model_path = './model/'+dpu_arch+'/asl_classifier.xmodel'
164+
model_path = './model_1/'+dpu_arch+'/asl_classifier_1.xmodel'
165165
print('[INFO] ASL model : ',model_path)
166166

167167
# Create DPU runner
@@ -205,6 +205,38 @@ def TopK(datain, size, filePath):
205205
rt_fps_message = "FPS: {0:.2f}".format(rt_fps)
206206
rt_fps_x = int(10*scale)
207207
rt_fps_y = int((frame_height-10)*scale)
208+
209+
id_to_class = {
210+
0 :"A",
211+
1 :"B",
212+
2 :"C",
213+
3 :"D",
214+
4 :"E",
215+
5 :"F",
216+
6 :"G",
217+
7 :"H",
218+
8 :"I",
219+
9 :"J",
220+
10:"K",
221+
11:"L",
222+
12:"M",
223+
13:"N",
224+
14:"O",
225+
15:"P",
226+
16:"Q",
227+
17:"R",
228+
18:"S",
229+
19:"T",
230+
20:"U",
231+
21:"V",
232+
22:"W",
233+
23:"X",
234+
24:"Y",
235+
25:"Z",
236+
26:"{del}",
237+
27:"{nothing}",
238+
28:"{space}"
239+
}
208240

209241
while True:
210242
# init the real-time FPS counter
@@ -239,36 +271,38 @@ def TopK(datain, size, filePath):
239271
#asl_y = model.predict(asl_x)
240272

241273
""" Prepare input/output buffers """
242-
print("[INFO] ASL - prep input buffer ")
274+
#print("[INFO] ASL - prep input buffer ")
243275
inputData = []
244276
inputData.append(np.empty((inputShape),dtype=np.int8,order='C'))
245277
inputImage = inputData[0]
246278
inputImage[0,...] = asl_img
247279

248-
print("[INFO] ASL - prep output buffer ")
280+
#print("[INFO] ASL - prep output buffer ")
249281
outputData = []
250282
outputData.append(np.empty((outputShape),dtype=np.int8,order='C'))
251283

252284
""" Execute model on DPU """
253-
print("[INFO] ASL - execute ")
285+
#print("[INFO] ASL - execute ")
254286
job_id = dpu.execute_async( inputData, outputData )
255287
dpu.wait(job_id)
256288

257289
# ASL post-processing
258-
print("[INFO] ASL - post-processing ")
259-
print(outputData[0].shape)
290+
#print("[INFO] ASL - post-processing ")
291+
#print(outputData[0].shape)
260292
OutputData = outputData[0].reshape(1,29)
261293
asl_y = np.reshape( OutputData, (-1,29) )
262294
asl_id = np.argmax(asl_y[0])
295+
asl_sign = id_to_class[asl_id]
263296

264-
print("[INFO] ASL - done ")
265-
cv2.putText(output,str(asl_id),(10,10),text_fontType,text_fontSize,text_color,text_lineSize,text_lineType)
297+
#print("[INFO] ASL - done ")
298+
asl_text = '['+str(asl_id)+']='+asl_sign
299+
cv2.putText(output,asl_text,(10,30),text_fontType,text_fontSize,text_color,text_lineSize,text_lineType)
266300

267301
#except:
268302
# print("ERROR : Exception occured during ASL classification ...")
269303

270304

271-
matching_text = ("[%04d] %02d"%(frame_count,asl_id))
305+
matching_text = ("[%04d] [%02d]=%s"%(frame_count,asl_id,asl_sign))
272306
print(matching_text)
273307

274308
# display real-time FPS counter (if valid)

0 commit comments

Comments
 (0)