code: def calc_rf(model, input_shape):
      for n, p in model.named_parameters():
          if not p.requires_grad:
              continue
          if "bias" in n:
              p.data.fill_(0)
          elif "weight" in n:
              p.data.fill_(1)
  
      input = torch.ones(input_shape, requires_grad=True)
      output = model(input)
      out_shape = output.size()
      ndims = len(out_shape)
      grad = torch.zeros(out_shape)
      l_tmp = []
      for i in xrange(ndims):
          if i == 0 or i == 1:  # batch or channel
              l_tmp.append(0)
          else:
              l_tmp.append(out_shape[i] / 2)
  
      grad[tuple(l_tmp)] = 1
      output.backward(gradient=grad)
      grad_np = img_.grad[0, 0].data.numpy()
      idx_nonzeros = np.where(grad_np != 0)
      RF = [np.max(idx) - np.min(idx) + 1 for idx in idx_nonzeros]
  
      return RF
  
file_path: tensorwatch/tensorwatch/model_graph/hiddenlayer/pytorch_builder.py
imports: from __future__ import absolute_import, division, print_function
  import re
  from .graph import Graph, Node
  from .None import transforms
  import torch
  from collections import abc
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: calc_rf(model, input_shape) and returns: RF