code: def test_netout_multiple_device(self):
      n_device = 4
      collector = OutputsCollector(n_devices=n_device)
      for idx in range(n_device):
          with tf.name_scope("worker_%d" % idx):
              image = tf.ones([2, 32, 32, 32, 1])
              foo = tf.zeros([2, 2])
              bar = tf.zeros([42])
              collector.add_to_collection(
                  name="image",
                  var=image,
                  collection=NETWORK_OUTPUT,
                  average_over_devices=False,
              )
              collector.add_to_collection(
                  name="foo",
                  var=foo,
                  collection=NETWORK_OUTPUT,
                  average_over_devices=False,
              )
              collector.add_to_collection(
                  name="bar",
                  var=bar,
                  collection=NETWORK_OUTPUT,
                  average_over_devices=True,
              )
      self.assertEqual(
          set(collector.variables(NETWORK_OUTPUT)),
          {
              "image_1",
              "image_3",
              "image_2",
              "image",
              "foo_1",
              "foo_2",
              "foo_3",
              "foo",
              "bar",
          },
      )
      self.assertEqual(
          len(collector.variables(NETWORK_OUTPUT)["bar"]), n_device
      )
      collector.finalise_output_op()
      self.assertIsInstance(
          collector.variables(NETWORK_OUTPUT)["bar"], tf.Tensor
      )
  
file_path: NiftyNet/tests/output_collector_test.py
imports: from __future__ import absolute_import, print_function
  import tensorflow
  from niftynet.engine.application_variables import NETWORK_OUTPUT, CONSOLE, TF_SUMMARIES
  from niftynet.engine.application_variables import OutputsCollector
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 4 for calling the OutputCollectorTest obj's underlying member method code with example usage: obj.test_netout_multiple_device() without return types