Skip to content

Commit 0d907ba

Browse files
committed
blazelandmark : update landmark code with explicit preprocess function, and document that pre-processing is already performed in extract_roi function. fix BGR versus RGB error in hailo implementation.
1 parent 5ea2563 commit 0d907ba

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

blaze_hailo/blazelandmark.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ def load_model(self, model_path):
8181
if self.DEBUG:
8282
print("[BlazeLandmark.load_model] Input Resolution : ",self.resolution)
8383

84+
def preprocess(self, x):
85+
# image was already pre-processed by extract_roi in blaze_common/blazebase.py
86+
# format = RGB
87+
# dtype = float32
88+
# range = 0.0 - 1.0
89+
90+
# Need to convert back to unsigned 8 bit for hailo implementation
91+
x = x * 255.0
92+
x = x.astype(np.uint8)
93+
return x
94+
8495
def predict(self, x):
8596

8697
self.profile_pre = 0.0
@@ -92,16 +103,16 @@ def predict(self, x):
92103
out3_list = []
93104

94105
#print("[BlazeLandmark] x ",x.shape,x.dtype)
106+
start = timer()
107+
x = self.preprocess(x)
108+
self.profile_pre += timer()-start
95109

96110
nb_images = x.shape[0]
97111
for i in range(nb_images):
98112

99113
# 1. Preprocess the images into tensors:
100114
start = timer()
101-
image_rgb = cv2.cvtColor(x[i,:,:,:], cv2.COLOR_BGR2RGB)
102-
image_norm = image_rgb * 255.0
103-
image_input = np.expand_dims(image_norm, axis=0)
104-
image_input = image_input.astype(np.uint8)
115+
image_input = np.expand_dims(x[i,:,:,:], axis=0)
105116
input_data = {self.input_vstream_infos[0].name: image_input}
106117
self.profile_pre += timer()-start
107118

blaze_pytorch/blazelandmark.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ def load_model(self, model_path):
4747
if self.DEBUG:
4848
print("[BlazeLandmark.load_model] Resolution : ",self.resolution)
4949

50+
def preprocess(self, x):
51+
# image was already pre-processed by extract_roi in blaze_common/blazebase.py
52+
# format = RGB
53+
# dtype = float32
54+
# range = 0.0 - 1.0
55+
return x
56+
5057
def predict(self, x):
5158

5259
self.profile_pre = 0.0
@@ -61,6 +68,7 @@ def predict(self, x):
6168
if isinstance(x, np.ndarray):
6269
x = torch.from_numpy(x).permute((0, 3, 1, 2))
6370
x = x.to(self.gpu_device)
71+
x = self.preprocess(x)
6472
self.profile_pre = timer()-start
6573

6674
#if self.DEBUG:

blaze_tflite/blazelandmark.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def load_model(self, model_path):
6060

6161
self.resolution = self.in_shape[1]
6262

63+
def preprocess(self, x):
64+
# image was already pre-processed by extract_roi in blaze_common/blazebase.py
65+
# format = RGB
66+
# dtype = float32
67+
# range = 0.0 - 1.0
68+
return x
69+
6370
def predict(self, x):
6471

6572
self.profile_pre = 0.0
@@ -71,7 +78,10 @@ def predict(self, x):
7178
#out3_list = []
7279

7380
#print("[BlazeLandmark] x ",x.shape,x.dtype)
74-
81+
start = timer()
82+
x = self.preprocess(x)
83+
self.profile_pre += timer()-start
84+
7585
nb_images = x.shape[0]
7686
for i in range(nb_images):
7787

blaze_vitisai/blazelandmark.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def load_model(self, model_path):
5656

5757
self.resolution = self.inputShape[1]
5858

59+
def preprocess(self, x):
60+
# image was already pre-processed by extract_roi in blaze_common/blazebase.py
61+
# format = RGB
62+
# dtype = float32
63+
# range = 0.0 - 1.0
64+
return x
65+
5966
def predict(self, x):
6067

6168
self.profile_pre = 0.0
@@ -67,6 +74,10 @@ def predict(self, x):
6774
out3_list = []
6875

6976
#print("[BlazeLandmark] x ",x.shape,x.dtype)
77+
start = timer()
78+
x = self.preprocess(x)
79+
self.profile_pre += timer()-start
80+
7081

7182
nb_images = x.shape[0]
7283
for i in range(nb_images):

0 commit comments

Comments
 (0)