code: def generate_anchors_3D(
      scales_xy,
      scales_z,
      ratios,
      shape,
      feature_stride_xy,
      feature_stride_z,
      anchor_stride,
  ):
      """
      scales: 1D array of anchor sizes in pixels. Example: [32, 64, 128]
      ratios: 1D array of anchor ratios of width/height. Example: [0.5, 1, 2]
      shape: [height, width] spatial shape of the feature map over which
              to generate anchors.
      feature_stride: Stride of the feature map relative to the image in pixels.
      anchor_stride: Stride of anchors on the feature map. For example, if the
          value is 2 then generate anchors for every other feature map pixel.
      """
      # Get all combinations of scales and ratios
  
      scales_xy, ratios_meshed = np.meshgrid(
          np.array(scales_xy), np.array(ratios)
      )
      scales_xy = scales_xy.flatten()
      ratios_meshed = ratios_meshed.flatten()
  
      # Enumerate heights and widths from scales and ratios
      heights = scales_xy / np.sqrt(ratios_meshed)
      widths = scales_xy * np.sqrt(ratios_meshed)
      depths = np.tile(
          np.array(scales_z),
          len(ratios_meshed) // np.array(scales_z)[..., None].shape[0],
      )
  
      # Enumerate shifts in feature space
      shifts_y = (
          np.arange(0, shape[0], anchor_stride) * feature_stride_xy
      )  # translate from fm positions to input coords.
      shifts_x = (
          np.arange(0, shape[1], anchor_stride) * feature_stride_xy
      )
      shifts_z = np.arange(0, shape[2], anchor_stride) * (
          feature_stride_z
      )
      shifts_x, shifts_y, shifts_z = np.meshgrid(
          shifts_x, shifts_y, shifts_z
      )
  
      # Enumerate combinations of shifts, widths, and heights
      box_widths, box_centers_x = np.meshgrid(widths, shifts_x)
      box_heights, box_centers_y = np.meshgrid(heights, shifts_y)
      box_depths, box_centers_z = np.meshgrid(depths, shifts_z)
  
      # Reshape to get a list of (y, x, z) and a list of (h, w, d)
      box_centers = np.stack(
          [box_centers_y, box_centers_x, box_centers_z], axis=2
      ).reshape([-1, 3])
      box_sizes = np.stack(
          [box_heights, box_widths, box_depths], axis=2
      ).reshape([-1, 3])
  
      # Convert to corner coordinates (y1, x1, y2, x2, z1, z2)
      boxes = np.concatenate(
          [
              box_centers - 0.5 * box_sizes,
              box_centers + 0.5 * box_sizes,
          ],
          axis=1,
      )
  
      boxes = np.transpose(
          np.array(
              [
                  boxes[:, 0],
                  boxes[:, 1],
                  boxes[:, 3],
                  boxes[:, 4],
                  boxes[:, 2],
                  boxes[:, 5],
              ]
          ),
          axes=(1, 0),
      )
      return boxes
  
imports: import numpy
  import scipy.misc
  import scipy.ndimage
  import torch
  from torch.autograd import Variable
  import torch.nn
label_desc: Use image node_id 8 for calling a global function with example usage: generate_anchors_3D(scales_xy, scales_z, ratios, shape, feature_stride_xy, feature_stride_z, anchor_stride) and returns: boxes