code: def compute_Conv2d_flops(module, inp, out):
      # Can have multiple inputs, getting the first one
      assert isinstance(module, nn.Conv2d)
      assert len(inp.size()) == 4 and len(inp.size()) == len(out.size())
  
      batch_size = inp.size()[0]
      in_c = inp.size()[1]
      k_h, k_w = module.kernel_size
      out_c, out_h, out_w = out.size()[1:]
      groups = module.groups
  
      filters_per_channel = out_c // groups
      conv_per_position_flops = k_h * k_w * in_c * filters_per_channel
      active_elements_count = batch_size * out_h * out_w
  
      total_conv_flops = conv_per_position_flops * active_elements_count
  
      bias_flops = 0
      if module.bias is not None:
          bias_flops = out_c * active_elements_count
  
      total_flops = total_conv_flops + bias_flops
      return total_flops
  
file_path: tensorwatch/tensorwatch/model_graph/torchstat/compute_flops.py
imports: import torch.nn
  import torch
  import numpy
  import math
label_desc: Use image node_id 2 for calling a global function with example usage: compute_Conv2d_flops(module, inp, out) and returns: total_flops