def calc_128_vec(self, img): face_img = utils.pre_process(img) # print('face image is: ', face_img.shape) facenet_inputs = [] facenet_outputs = [] facenet_inputs.append(tritonclient.http.InferInput(self.Facenet_inputs[0], face_img.shape, 'FP32')) facenet_inputs[0].set_data_from_numpy(face_img.astype(np.float32), binary_data=True) facenet_outputs.append(tritonclient.http.InferRequestedOutput(self.Facenet_outputs[0], binary_data=True)) output = self.triton_client.infer("facenet_tf", inputs=facenet_inputs, outputs=facenet_outputs) pre = output.as_numpy(self.Facenet_outputs[0]) pre = utils.l2_normalize(np.concatenate(pre)) pre = np.reshape(pre, [128]) # print('pre is: ', pre.shape) return pre
def aggregate_templates(templates, features, method, T=1.0): for i,t in enumerate(templates): if len(t.indices) > 0: if method == 'mean': t.feature = utils.l2_normalize(np.mean(features[t.indices], axis=0)) if method == 'PFE_fuse': t.mu, t.sigma_sq = utils.aggregate_PFE(features[t.indices], normalize=True, concatenate=False, T=T) t.feature = t.mu if method == 'PFE_fuse_match': if not hasattr(t, 'mu'): t.mu, t.sigma_sq = utils.aggregate_PFE(features[t.indices], normalize=True, concatenate=False, T=T) t.feature = np.concatenate([t.mu, t.sigma_sq]) else: t.feature = None if i % 1000 == 0: sys.stdout.write('Fusing templates {}/{}...\t\r'.format(i, len(templates))) print('')