code: def test_if_net(self):
      with NetBuilder() as nb:
          x0 = ops.Const(0)
          x1 = ops.Const(1)
          x2 = ops.Const(2)
          y0 = ops.Const(0)
          y1 = ops.Const(1)
          y2 = ops.Const(2)
  
          # basic logic
          first_res = ops.Const(0)
          with ops.IfNet(ops.Const(True)):
              ops.Const(1, blob_out=first_res)
          with ops.Else():
              ops.Const(2, blob_out=first_res)
  
          second_res = ops.Const(0)
          with ops.IfNet(ops.Const(False)):
              ops.Const(1, blob_out=second_res)
          with ops.Else():
              ops.Const(2, blob_out=second_res)
  
          # nested and sequential ifs,
          # empty then/else,
          # passing outer blobs into branches,
          # writing into outer blobs, incl. into input blob
          # using local blobs
          with ops.IfNet(ops.LT([x0, x1])):
              local_blob = ops.Const(900)
              ops.Add([ops.Const(100), local_blob], [y0])
  
              gt = ops.GT([x1, x2])
              with ops.IfNet(gt):
                  # empty then
                  pass
              with ops.Else():
                  ops.Add([y1, local_blob], [local_blob])
                  ops.Add([ops.Const(100), y1], [y1])
  
              with ops.IfNet(ops.EQ([local_blob, ops.Const(901)])):
                  ops.Const(7, blob_out=y2)
                  ops.Add([y1, y2], [y2])
          with ops.Else():
              # empty else
              pass
  
      plan = Plan("if_net_test")
      plan.AddStep(to_execution_step(nb))
      ws = workspace.C.Workspace()
      ws.run(plan)
  
      first_res_value = ws.blobs[str(first_res)].fetch()
      second_res_value = ws.blobs[str(second_res)].fetch()
      y0_value = ws.blobs[str(y0)].fetch()
      y1_value = ws.blobs[str(y1)].fetch()
      y2_value = ws.blobs[str(y2)].fetch()
  
      self.assertEqual(first_res_value, 1)
      self.assertEqual(second_res_value, 2)
      self.assertEqual(y0_value, 1000)
      self.assertEqual(y1_value, 101)
      self.assertEqual(y2_value, 108)
      self.assertTrue(str(local_blob) not in ws.blobs)
  
imports: from caffe2.python import workspace
  from caffe2.python.core import Plan, to_execution_step, Net
  from caffe2.python.task import Task, TaskGroup, final_output
  from caffe2.python.net_builder import ops, NetBuilder
  from caffe2.python.session import LocalSession
  import unittest
  import threading
label_desc: Use image node_id 9 for calling the TestNetBuilder obj's underlying member method code with example usage: obj.test_if_net() without return types