code: def measure_model(model, H, W, device):
      global count_ops, count_params
      count_ops = 0
      count_params = 0
      data = torch.zeros(2, 3, H, W).to(device)
  
      def should_measure(x):
          return is_leaf(x)
  
      def modify_forward(model):
          for child in model.children():
              if should_measure(child):
  
                  def new_forward(m):
                      def lambda_forward(x):
                          measure_layer(m, x)
                          return m.old_forward(x)
  
                      return lambda_forward
  
                  child.old_forward = child.forward
                  child.forward = new_forward(child)
              else:
                  modify_forward(child)
  
      def restore_forward(model):
          for child in model.children():
              # leaf node
              if is_leaf(child) and hasattr(child, "old_forward"):
                  child.forward = child.old_forward
                  child.old_forward = None
              else:
                  restore_forward(child)
  
      modify_forward(model)
      model.forward(data)
      restore_forward(model)
  
      return count_ops, count_params
  
imports: import torch
label_desc: Use image node_id 6 for calling a global function with example usage: measure_model(model, H, W, device) and returns: count_ops,  count_params, is_leaf, lambda_forward, m