Skip to content

Commit 9b13ee1

Browse files
committed
blaze_hailo: First working version of hand_landmark_lit/full and palm_detection_lite/full models.
1 parent c14dfd7 commit 9b13ee1

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

blaze_hailo/blazedetector.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import cv2
23

34
from blazebase import BlazeDetectorBase
45

@@ -108,11 +109,10 @@ def load_model(self, model_path):
108109
# Create input and output virtual streams params
109110
# Quantized argument signifies whether or not the incoming data is already quantized.
110111
# Data is quantized by HailoRT if and only if quantized == False .
111-
self.input_vstreams_params = InputVStreamParams.make(self.network_group, quantized=False,
112-
format_type=FormatType.FLOAT32)
113-
self.output_vstreams_params = OutputVStreamParams.make(self.network_group, quantized=True,
114-
format_type=FormatType.UINT8)
115-
#format_type=FormatType.FLOAT32)
112+
#self.input_vstreams_params = InputVStreamParams.make(self.network_group, quantized=False, format_type=FormatType.FLOAT32)
113+
#self.output_vstreams_params = OutputVStreamParams.make(self.network_group, quantized=True, format_type=FormatType.UINT8)
114+
self.input_vstreams_params = InputVStreamParams.make(self.network_group)
115+
self.output_vstreams_params = OutputVStreamParams.make(self.network_group, format_type=FormatType.FLOAT32)
116116

117117
# Define dataset params
118118
self.input_vstream_infos = self.hef.get_input_vstream_infos()
@@ -193,8 +193,11 @@ def load_model(self, model_path):
193193

194194
def preprocess(self, x):
195195
"""Converts the image pixels to the range [-1, 1]."""
196-
x = (x / 255.0)
197-
x = x.astype(np.float32)
196+
#x = (x / 255.0)
197+
#x = x.astype(np.float32)
198+
199+
#x = cv2.cvtColor(x, cv2.COLOR_BGR2RGB)
200+
x = x.astype(np.uint8)
198201

199202
return x
200203

@@ -271,11 +274,10 @@ def predict_on_batch(self, x):
271274
# Create input and output virtual streams params
272275
# Quantized argument signifies whether or not the incoming data is already quantized.
273276
# Data is quantized by HailoRT if and only if quantized == False .
274-
self.input_vstreams_params = InputVStreamParams.make(self.network_group, quantized=False,
275-
format_type=FormatType.FLOAT32)
276-
self.output_vstreams_params = OutputVStreamParams.make(self.network_group, quantized=True,
277-
format_type=FormatType.UINT8)
278-
#format_type=FormatType.FLOAT32)
277+
#self.input_vstreams_params = InputVStreamParams.make(self.network_group, quantized=False, format_type=FormatType.FLOAT32)
278+
#self.output_vstreams_params = OutputVStreamParams.make(self.network_group, quantized=True, format_type=FormatType.UINT8)
279+
self.input_vstreams_params = InputVStreamParams.make(self.network_group)
280+
self.output_vstreams_params = OutputVStreamParams.make(self.network_group, format_type=FormatType.FLOAT32)
279281

280282
with InferVStreams(self.network_group, self.input_vstreams_params, self.output_vstreams_params) as infer_pipeline:
281283
with self.network_group.activate(self.network_group_params):

blaze_hailo/blazelandmark.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import cv2
23

34
from blazebase import BlazeLandmarkBase
45

@@ -141,8 +142,8 @@ def load_model(self, model_path):
141142
#[BlazeDetector.load_model] Output[ 3 ] Shape : (1,)
142143

143144
self.inputShape = self.input_vstream_infos[0].shape
144-
self.outputShape1 = tuple(self.output_vstream_infos[0].shape)
145-
self.outputShape2 = tuple(self.output_vstream_infos[1].shape)
145+
self.outputShape1 = tuple(self.output_vstream_infos[2].shape)
146+
self.outputShape2 = tuple(self.output_vstream_infos[0].shape)
146147

147148
if self.DEBUG:
148149
print("[BlazeLandmark.load_model] Input Shape : ",self.inputShape)
@@ -173,9 +174,11 @@ def predict(self, x):
173174

174175
# 1. Preprocess the images into tensors:
175176
start = timer()
176-
xi = np.expand_dims(x[i,:,:,:], axis=0)
177-
xi = xi * 255.0
178-
input_data = {self.input_vstream_infos[0].name: xi}
177+
image_rgb = cv2.cvtColor(x[i,:,:,:], cv2.COLOR_BGR2RGB)
178+
image_norm = image_rgb * 255.0
179+
image_input = np.expand_dims(image_norm, axis=0)
180+
image_input = image_input.astype(np.uint8)
181+
input_data = {self.input_vstream_infos[0].name: image_input}
179182
self.profile_pre += timer()-start
180183

181184
# 2. Run the neural network:
@@ -193,11 +196,10 @@ def predict(self, x):
193196
# Create input and output virtual streams params
194197
# Quantized argument signifies whether or not the incoming data is already quantized.
195198
# Data is quantized by HailoRT if and only if quantized == False .
196-
self.input_vstreams_params = InputVStreamParams.make(self.network_group, quantized=False,
197-
format_type=FormatType.FLOAT32)
198-
self.output_vstreams_params = OutputVStreamParams.make(self.network_group, quantized=True,
199-
format_type=FormatType.UINT8)
200-
#format_type=FormatType.FLOAT32)
199+
#self.input_vstreams_params = InputVStreamParams.make(self.network_group, quantized=False, format_type=FormatType.FLOAT32)
200+
#self.output_vstreams_params = OutputVStreamParams.make(self.network_group, quantized=True, format_type=FormatType.UINT8)
201+
self.input_vstreams_params = InputVStreamParams.make(self.network_group)
202+
self.output_vstreams_params = OutputVStreamParams.make(self.network_group, format_type=FormatType.FLOAT32)
201203

202204
with InferVStreams(self.network_group, self.input_vstreams_params, self.output_vstreams_params) as infer_pipeline:
203205
with self.network_group.activate(self.network_group_params):
@@ -210,12 +212,12 @@ def predict(self, x):
210212
out1 = infer_results[self.output_vstream_infos[2].name]
211213
handedness = infer_results[self.output_vstream_infos[3].name]
212214
out2 = infer_results[self.output_vstream_infos[0].name]
213-
out2 = out2.reshape(1,21,-1) # 42 => [1,21,2]
215+
out2 = out2.reshape(1,21,-1) # 42 => [1,21,2] | 63 => [1,21,3]
214216
out2 = out2/self.resolution
215217
elif self.blaze_app == "blazefacelandmark":
216218
out1 = infer_results[self.output_vstream_infos[0].name]
217219
out2 = infer_results[self.output_vstream_infos[1].name]
218-
out2 = out2.reshape(1,-1,3) # 1404 => [1,356,2]
220+
out2 = out2.reshape(1,-1,3) # 1404 => [1,356,3]
219221
out2 = out2/self.resolution
220222
elif self.blaze_app == "blazeposelandmark":
221223
out1 = infer_results[self.output_vstream_infos[0].name]

0 commit comments

Comments
 (0)