code: def _calc_batch_metrics(
      output,
      labels,
      weights,
      actual_seq_len,
      actual_batch_len,
      loss_per_sec,
  ):
      prediction = _np.argmax(output, axis=-1)
      prediction = _np.expand_dims(prediction, 2)
      accuracy = (prediction == labels) * (weights > 0)
      acc_per_seq = _np.sum(accuracy, axis=1).astype(float) / (
          actual_seq_len + 1e-5
      )
      batch_accuracy = _np.sum(acc_per_seq).astype(float) / (
          actual_batch_len + 1e-5
      )
      batch_loss = _np.sum(loss_per_sec)
  
      return batch_loss, batch_accuracy, acc_per_seq
  
file_path: turicreate/src/python/turicreate/toolkits/activity_classifier/_mps_model_architecture.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from .._mps_utils import MpsLowLevelAPI, MpsLowLevelNetworkType, MpsLowLevelMode
label_desc: Use image node_id 2 for calling a global function with example usage: _calc_batch_metrics(output, labels, weights, actual_seq_len, actual_batch_len, loss_per_sec) and returns: batch_loss,  batch_accuracy,  acc_per_seq