code: def ReferenceDepthwiseConv2D(
      input_tensor, filter_tensor, strides, padding, data_format=None
  ):
      # Reference implementation of depthwise convolution that uses regular
      # convolution.
      convs = []
      in_channels = filter_tensor.shape[2]
      # Use a custom implementation of depthwise conv2d using slicing.
      for channel in range(in_channels):
          # Slice the input along channel
          if data_format == "NCHW":
              input_slice = input_tensor[:, channel : channel + 1, :, :]
          else:
              input_slice = input_tensor[:, :, :, channel : channel + 1]
  
          # Slice the filters.  Filters are  H, W, InC, DepthMultiplier
          filter_slice = filter_tensor[:, :, channel : channel + 1, :]
          # Do conv
          convs.append(
              nn_ops.conv2d(
                  input_slice,
                  filter_slice,
                  strides,
                  padding,
                  data_format=data_format,
                  name="depthwise_slice_%d" % channel,
              )
          )
  
      # Concat along dimension.
      if data_format == "NCHW":
          return array_ops.concat(convs, 1)
      else:
          return array_ops.concat(convs, 3)
  
imports: import numpy
  from tensorflow.compiler.tests import xla_test
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import nn_impl
  from tensorflow.python.ops import nn_ops
  import tensorflow.python.ops.nn_grad
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling a global function with example usage: ReferenceDepthwiseConv2D(input_tensor, filter_tensor, strides, padding, data_format) and returns: array_ops, array_ops