title: ValueError: None values not supported Keras Custom Loss Function in Tensorflow
body: <p>I get the following error in the fit stage of a Keras sequential model using a custom objective function written using TensorFlow.</p>
  
  <pre><code>File "basicCNN.py", line 110, in &lt;module&gt;
  callbacks=[TensorBoard(log_dir="./logs/{}".format(now))])
  File "/home/garethjones/.local/lib/python2.7/site-packages/keras/models.py", line 664, in fit
  sample_weight=sample_weight)
  File "/home/garethjones/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1115, in fit
  self._make_train_function()
  File "/home/garethjones/.local/lib/python2.7/site-packages/keras/engine/training.py", line 713, in _make_train_function
  self.total_loss)
  File "/home/garethjones/.local/lib/python2.7/site-packages/keras/optimizers.py", line 391, in get_updates
  m_t = (self.beta_1 * m) + (1. - self.beta_1) * g
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py", line 813, in binary_op_wrapper
  y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor
  ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function
  return constant(v, dtype=dtype, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 165, in constant
  tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 360, in make_tensor_proto
  raise ValueError("None values not supported.")
  </code></pre>
  
  <p>My custom function is this</p>
  
  <pre><code>def PAI(y_true, y_pred, k):
      '''
      Args:
          y_true (tensor): (batch x numCells)
          y_pred (tensor): (batch x numCells)
          k: The optimal number of hotspots
          area: 
      Returns:
          cfsRatio (tensor): The inverse of the percentage of crimes in hotspots per observation
      '''
      # Compute total crime for each obs
      totalCFS =  tf.reduce_sum(y_true,  axis=1)  # batch x 1
      # Flatten for gather
      flatTruth = tf.reshape(y_true, [-1])  # 1 x batch * numCells
      # Select top candidate cells
      _, predHS = tf.nn.top_k(y_true, k)
      # Convert indices for gather
      predHSFlat = tf.range(0, tf.shape(y_true)[0]) * tf.shape(y_true)[1] + predHS)
      # Map hotspot predictions to crimes
      hsCFS = tf.gather(flatTruth, predHSFlat)
      # Number of crimes commited in hotspots
      hsCFSsum = tf.reduce_sum(hsCFS, axis=1) # batch x 1
      # Ratio of crimes committed in hotspots and inverted for minimization
      cfsRatio = tf.truediv(1.0, tf.truediv(hsCFSsum, totalCFS))
  
      return cfsRatio
  </code></pre>
  
  <p>I can run this when I have an interactive session. The function primarily relies on code from this Tensorflow issue <a href="https://github.com/tensorflow/tensorflow/issues/206" rel="nofollow noreferrer">https://github.com/tensorflow/tensorflow/issues/206</a> .</p>