title: Why am I unable to use tf.nn.conv2d when I call it through an other function?
body: <p>I am trying to do data augmentation over a dataset.
  I have different kind of modifiers, one of them is the Gaussian Blur.
  I used to map it with <code>tf.nn.conv3d</code> but in order to make it faster, I changed it to <code>tf.nn.conv2d</code> (using 3d was not optimal). However now, when I run it, I get </p>
  
  <pre><code>tensorflow.python.framework.errors_impl.UnimplementedError: Generic conv implementation only supports NHWC tensor format for now.
  </code></pre>
  
  <p>I don't understand why because I'm already trying to run it with <code>data_format='NHWC'</code>.</p>
  
  <p>Here is the code :</p>
  
  <pre class="lang-py prettyprint-override"><code>my current file :
  with tf.name_scope('DataAugmentation'):
      for modifier in modifiers:
          def apply_modifier(t_imgs,t_lbls,t_ranges,t_img_paths):
              t_imgs, t_lbls = modifier.apply_to(t_imgs, t_lbls)
                     return t_imgs,t_lbls,t_ranges,t_img_paths
  
          ds = ds.map(apply_modifier)
  </code></pre>
  
  <p>In an other file, the method of the modifier which raises the issue  :</p>
  
  <pre class="lang-py prettyprint-override"><code>    self.k_conv = ........
      def apply_to(self, t_imgs, t_lbls):
          with tf.name_scope('GaussianBlur'):            
              t_imgs = tf.nn.conv2d(t_imgs,self.k_conv,
                         strides=[1, 1, 1, 1], 
                         padding='SAME',
                         data_format='NHWC'
                         )
              return (t_imgs, t_lbls)
  </code></pre>
  
  <p>The very strange point is that I can run the program if I declare the function in my current file instead of in an other file where I define the class modifier :</p>
  
  <pre class="lang-py prettyprint-override"><code>        with tf.name_scope('DataAugmentation'):
              for modifier in modifiers:
                  if modifier.m.NAME=='GaussianBlur':
                      k_conv = create.random_k_conv()
                      def apply_modifier(t_imgs,t_lbls,t_ranges,t_img_paths):
  
                          t_imgs = tf.nn.conv2d(t_imgs,k_conv,
                                                strides=[1,1,1,1],
                                                padding='SAME'
                                                )
                          return t_imgs,t_lbls,t_ranges,t_img_paths
                  else:
                      def apply_modifier(t_imgs,t_lbls,t_ranges,t_img_paths):
                          t_imgs, t_lbls = modifier.apply_to(t_imgs, t_lbls)
                          return t_imgs,t_lbls,t_ranges,t_img_paths
                  ds = ds.map(apply_modifier)
  
  </code></pre>
  
  <p>The type of my dataset is </p>
  
  <pre><code>&lt;BatchDataset shapes: ((?, 500, 500, 1), (?, 6, 6, 5), (?, 2), (?,)), types (tf.float32, tf.float32, tf.float32, tf.string)&gt;```
  
  I really have no idea why the second code runs but not the first one, it s been a few days I am stuck.
  
  Thank you for reading, I hope someone could help.
  </code></pre>