How to create custom Keras metric using multiple functions with numpy arrays and matrices? I'm training a model for predicting position and orientation using regression.
I want to implement custom metric using last 3 values of model output to calculate and minimize angular error defined by function like this:
def angular_error(data_true, data_pred):

  # Axes orientation in radians (X,Y,Z)
  axes_orientation_gt = np.transpose(data_true[2:5])
  axes_orientation_pred = np.transpose(data_pred[2:5])

  axes_size = 0.1  # Axes_size in meters

  # Convert euler angles to rotation matrix (XYZ)
  _, Rx_gt, Ry_gt, Rz_gt = eul2rotmat(axes_orientation_gt)

  # Rotation matrix XYZ
  R_gt = Rz_gt * Ry_gt * Rx_gt

  # Y-axis end
  y_a_gt = R_gt * np.transpose(np.matrix([0, 1, 0])) * axes_size

  # Predictions
  # Convert euler angles to rotation matrix (XYZ)
  _, Rx_dnn, Ry_dnn, Rz_dnn = eul2rotmat(axes_orientation_pred)

  # Rotation matrix XYZ
  R_dnn = Rz_dnn * Ry_dnn * Rx_dnn

  ....

  return gaze_ang_err

Is there a way to avoid using Keras/TF functions instead of every numpy function appearance/usage? This function also calls two more functions with numpy and math operations so it seems like an overkill.
Any input appreciated...
Solved it using tf.py_function() as a wrapper function around the angular_error() function and added it to callbacks.