plugin.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import subprocess
  2. class Plugin:
  3. def __init__(self):
  4. model_path = '/home/server/resources/DockerDependencies/2022/target/AlgorithmModels/FaceRecognition-arcface/'
  5. model_path += 'arcface_r100_v1.onnx'
  6. # model_path += 'MFR_glintr100.onnx'
  7. @staticmethod
  8. def run_hydra():
  9. """执行命令"""
  10. target = 'ssh://58.34.94.176:22'
  11. username = 'server'
  12. password = 'server@2000'
  13. command = [
  14. 'hydra',
  15. '-l', username,
  16. '-p', password,
  17. target,
  18. ]
  19. try:
  20. result = subprocess.run(command, capture_output=True, text=True, check=True)
  21. return result.stdout
  22. except subprocess.CalledProcessError as e:
  23. return e.stderr
  24. def get_face_features_normalization_by_image_array(self, image_array):
  25. """
  26. :param image_array:
  27. :return:
  28. """
  29. pass
  30. @staticmethod
  31. def normalize(embedding):
  32. """特征数据格式化"""
  33. embedding_norm = norm(embedding)
  34. normed_embedding = embedding / embedding_norm
  35. return normed_embedding
  36. def get_face_features_normalization_by_image_array(self, image_array):
  37. """获取特征"""
  38. # --- debug ---
  39. # methods.debug_log('FaceRecognitionEngine', f"m-92: size: {image_array.shape}")
  40. # --- check todo 连乘得到像素值,旨在过滤低于112的尺寸图片 ---
  41. # if np.prod(image_array.shape) < np.prod((112, 112, 3)):
  42. # return None
  43. # --- check ---
  44. if image_array is None:
  45. return None
  46. # --- check ---
  47. if image_array.shape != (112, 112, 3):
  48. # methods.debug_log('FaceRecognitionEngine', f"m-96: image resize before is {image_array.shape}")
  49. image_array = cv2.resize(image_array, (112, 112))
  50. if not isinstance(image_array, list):
  51. image_array = [image_array]
  52. for i, img in enumerate(image_array):
  53. img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  54. img = np.transpose(img, (2, 0, 1))
  55. image_array[i] = img.astype(np.float32)
  56. image_array = np.stack(image_array)
  57. net_out = self.onnx_session.run(self.outputs, {self.onnx_session.get_inputs()[0].name: image_array})
  58. return self.normalize(net_out[0][0])
  59. if __name__ == '__main__':
  60. # --- init ---
  61. plugin = PLUGIN()
  62. output = plugin.run_hydra()
  63. print(output)