code: def bprop_roipooling_ref(
      fm,
      rois,
      error,
      fm_channel,
      fm_height,
      fm_width,
      bsz,
      rois_per_image,
      H,
      W,
  ):
      """
      Function to perform a bprop of ROIPooling. It uses a different way from the
      that in CPU backend
      """
      feature_maps = fm.reshape(fm_channel, fm_height, fm_width, bsz)
      rois_per_batch = rois_per_image * bsz
      error_in = error.reshape(fm_channel, H, W, rois_per_batch)
  
      delta = np.zeros(feature_maps.shape).reshape(
          fm_channel, fm_height, fm_width, bsz
      )
  
      # combine the feature map with ROIs
      for b_id in range(rois_per_batch):
          [idx, xmin, ymin, xmax, ymax] = rois[b_id]
          xmin = int(round(xmin * spatial_scale))
          xmax = int(round(xmax * spatial_scale))
          ymin = int(round(ymin * spatial_scale))
          ymax = int(round(ymax * spatial_scale))
          roi_width = max(xmax - xmin + 1, 1)
          roi_height = max(ymax - ymin + 1, 1)
  
          stride_h = float(roi_height) / float(H)
          stride_w = float(roi_width) / float(W)
  
          for h_out in range(H):
              sliceh, lenh = _fprop_slice_np(
                  h_out, stride_h, fm_height, ymin
              )
              if sliceh.stop <= sliceh.start:
                  continue
              for w_out in range(W):
                  slicew, lenw = _fprop_slice_np(
                      w_out, stride_w, fm_width, xmin
                  )
                  if slicew.stop <= slicew.start:
                      continue
                  else:
                      array_I = feature_maps[
                          :, sliceh, slicew, int(idx)
                      ].reshape(fm_channel, -1)
                      max_idx = np.argmax(array_I, axis=1)
  
                      delta_view = delta[
                          :, sliceh, slicew, int(idx)
                      ].reshape(fm_channel, -1)
                      delta_view[
                          list(range(fm_channel)), max_idx
                      ] += error_in[:, h_out, w_out, b_id]
                      delta[
                          :, sliceh, slicew, int(idx)
                      ] = delta_view.reshape(fm_channel, lenh, lenw)
  
      return delta
  
file_path: neon/tests/test_roipooling_layer.py
imports: from builtins import round
  import itertools
  import numpy
  from timeit import default_timer
  from neon import NervanaObject, logger
  from neon.backends import gen_backend
  from utils import allclose_with_out
label_desc: Use image node_id 3 for calling a global function with example usage: bprop_roipooling_ref(fm, rois, error, fm_channel, fm_height, fm_width, bsz, rois_per_image, H, W) and returns: delta