code: def testMultilabelMatch3(self):
      predictions = np.random.randint(1, 5, size=(100, 1, 1, 1))
      targets = np.random.randint(1, 5, size=(100, 10, 1, 1))
      weights = np.random.randint(0, 2, size=(100, 1, 1, 1))
      targets *= weights
  
      predictions_repeat = np.repeat(predictions, 10, axis=1)
      expected = (predictions_repeat == targets).astype(float)
      expected = np.sum(expected, axis=(1, 2, 3))
      expected = np.minimum(expected / 3.0, 1.0)
      expected = (
          np.sum(expected * weights[:, 0, 0, 0]) / weights.shape[0]
      )
      with self.test_session() as session:
          scores, weights_ = metrics.multilabel_accuracy_match3(
              tf.one_hot(predictions, depth=5, dtype=tf.float32),
              tf.constant(targets, dtype=tf.int32),
          )
          a, a_op = tf.metrics.mean(scores, weights_)
          session.run(tf.local_variables_initializer())
          session.run(tf.global_variables_initializer())
          _ = session.run(a_op)
          actual = session.run(a)
      self.assertAlmostEqual(actual, expected, places=6)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from tensor2tensor.utils import metrics
  import tensorflow.compat.v1
label_desc: Use image node_id 21 for calling the MetricsTest obj's underlying member method code with example usage: obj.testMultilabelMatch3() without return types