in source/simulate/detector.py [0:0]
def face_detect_simulate(self):
image_names = [f for f in os.listdir(self._faces_detect_root_dir) if f.startswith('test_')]
image_names = sorted(image_names)
for name in image_names:
full_path = os.path.join(self._faces_detect_root_dir, name)
print('Test image {}:'.format(full_path))
# Step 1: read image and execute base64 encoding
image_base64_enc = self.get_base64_encoding(full_path)
# Step 2: send request to backend
request_body = {
"timestamp": str(time.time()),
"request_id": 1242322,
"image_base64_enc": image_base64_enc
}
t1 = time.time()
response = requests.post(self._face_detect_url, data=json.dumps(request_body))
t2 = time.time()
print('Time cost = {}'.format(t2 - t1))
# Step 3: visualization
response = json.loads(response.text)
print('Response = {}'.format(response))
bbox_coords = np.array(response['bbox_coords'])
bbox_scores = np.array(response['bbox_scores'])
class_ids = np.zeros(shape=(bbox_scores.shape[0], ))
print('bbox_coords.shape = {}'.format(bbox_coords.shape))
print('bbox_scores.shape = {}'.format(bbox_scores.shape))
self.visualize(full_path, bbox_coords, bbox_scores, class_ids, label_name='face')