code: def validate(
      self, image_shape, filter_shape, out_dim, verify_grad=True
  ):
      image_dim = len(image_shape)
      filter_dim = len(filter_shape)
      input = T.TensorType("float64", [False] * image_dim)()
      filters = T.TensorType("float64", [False] * filter_dim)()
  
      bsize = image_shape[0]
      if image_dim != 3:
          bsize = 1
      nkern = filter_shape[0]
      if filter_dim != 3:
          nkern = 1
  
      # THEANO IMPLEMENTATION ############
      # we create a symbolic function so that verify_grad can work
      def sym_conv2d(input, filters):
          return conv.conv2d(input, filters)
  
      output = sym_conv2d(input, filters)
      assert output.ndim == out_dim
      theano_conv = theano.function([input, filters], output)
  
      # initialize input and compute result
      image_data = np.random.random(image_shape)
      filter_data = np.random.random(filter_shape)
      theano_output = theano_conv(image_data, filter_data)
  
      # REFERENCE IMPLEMENTATION ############
      out_shape2d = (
          np.array(image_shape[-2:]) - np.array(filter_shape[-2:]) + 1
      )
      ref_output = np.zeros(tuple(out_shape2d))
  
      # reshape as 3D input tensors to make life easier
      image_data3d = image_data.reshape((bsize,) + image_shape[-2:])
      filter_data3d = filter_data.reshape((nkern,) + filter_shape[-2:])
      # reshape theano output as 4D to make life easier
      theano_output4d = theano_output.reshape(
          (
              bsize,
              nkern,
          )
          + theano_output.shape[-2:]
      )
  
      # loop over mini-batches (if required)
      for b in range(bsize):
          # loop over filters (if required)
          for k in range(nkern):
              image2d = image_data3d[b, :, :]
              filter2d = filter_data3d[k, :, :]
              output2d = np.zeros(ref_output.shape)
              for row in range(ref_output.shape[0]):
                  for col in range(ref_output.shape[1]):
                      output2d[row, col] += (
                          image2d[
                              row : row + filter2d.shape[0],
                              col : col + filter2d.shape[1],
                          ]
                          * filter2d[::-1, ::-1]
                      ).sum()
  
              self.assertTrue(
                  _allclose(theano_output4d[b, k, :, :], output2d)
              )
  
      # TEST GRADIENT ############
      if verify_grad:
          utt.verify_grad(sym_conv2d, [image_data, filter_data])
  
file_path: Theano/theano/tensor/signal/tests/test_conv.py
imports: from __future__ import absolute_import, print_function, division
  import unittest
  from nose.plugins.skip import SkipTest
  import numpy
  import theano
  import theano.tensor
  from theano.tests import unittest_tools
  from theano.tensor.signal import conv
  from theano.tensor.basic import _allclose
label_desc: Use image node_id 2 for calling the TestSignalConv2D obj's underlying member method code with example usage: obj.validate(image_shape, filter_shape, out_dim, verify_grad) and returns: conv