title: TypeError: 'Tensor' object cannot be interpreted as an integer when using tf.map_fn()
body: <p>I am trying to construct label-dependent convolutional filters in keras/tensorflow. Therefore, the convolutional filter(s) depend on each example in the batch.</p>
  <pre><code># function used for tf.map_fn
  def single_conv(tupl):
      x, kernel = tupl
      return tf.nn.conv2d(x, kernel, strides=(1, 1, 1, 1), padding='SAME')
  
  # first dimension is None (batch size)
  input_img = tf.keras.layers.Input(shape=(28,28,1), dtype=tf.float32)
  label = tf.keras.layers.Input(shape=(10,), dtype=tf.float32) 
  
  # the network is learning a mapping for the label
  label_encoded = tf.keras.layers.Dense(9, activation='relu')(label) 
  # turn mapping into conv filter 
  kernels = tf.keras.layers.Reshape((3,3,1,1))(label_encoded) 
  
  # class dependent filter(s)
  conditional_conv = tf.map_fn(single_conv, (tf.expand_dims(input_img, 1), kernels), fn_output_signature=tf.float32) 
  </code></pre>
  <p>When I run this code snippet, I get a <code>TypeError: 'Tensor' object cannot be interpreted as an integer</code> for the last line. Since the last line uses <code>tf.map_fn</code>, I saw that  tf.map_fn results in a TypeError if either the function used (single_conv in this case) is not callable or the structure of the output of function and fn_output_signature do not match: <a href="https://www.tensorflow.org/api_docs/python/tf/map_fn#raises" rel="nofollow noreferrer">https://www.tensorflow.org/api_docs/python/tf/map_fn#raises</a>.</p>
  <p>However, I'm still not sure why this is happening? I feel like both of those reasons should not be an issue?</p>