title: tensorflow: Get ValueError("None values not supported.") on batch normalization
body: <p>I'm using batch normalization via tensorflow. The problem is that it seems the network must use a <code>tf.cond</code> operator in the batchnorm layer, otherwise it will report the following error:</p>
  
  <pre><code>ValueError("None values not supported.")
  </code></pre>
  
  <p>I'm confused about this. I post a simple example in the following:</p>
  
  <pre><code>conv_bias = some_layer_defined_previously
  train = tf.cast((True), tf.bool)
  conv_bias = self.batch_norm2(conv_bias, filters, train)
  </code></pre>
  
  <p>This network will work well. However, if I change it to the following:</p>
  
  <pre><code>conv_bias = some_layer_defined_previously
  train = True
  conv_bias = self.batch_norm3(conv_bias, filters, train)
  </code></pre>
  
  <p>Then the error happens. </p>
  
  <p>I'm confused because the only difference between the two networks is the batchnorm layer. The definitions of the two batchnorm layers are as follows:</p>
  
  <p>batchnorm2</p>
  
  <pre><code>def batch_norm2(self, x, size, training, decay=0.999):
      beta = tf.Variable(tf.zeros([size]), name='beta')
      scale = tf.Variable(tf.ones([size]), name='scale')
      pop_mean = tf.Variable(tf.zeros([size]), 'mean')
      pop_var = tf.Variable(tf.ones([size]), 'var')
      epsilon = 1e-3
      self.model_params += [beta, scale, pop_mean, pop_var]
      batch_mean, batch_var = tf.nn.moments(x, [0, 1, 2])
      train_mean = tf.assign(pop_mean, pop_mean * decay + batch_mean * (1 - decay))
      train_var = tf.assign(pop_var, pop_var * decay + batch_var * (1 - decay))
  
      def batch_statistics():
          with tf.control_dependencies([train_mean, train_var]):
              return tf.nn.batch_normalization(x, batch_mean, batch_var, beta, scale, epsilon, name='batch_norm')
  
      def population_statistics():
          return tf.nn.batch_normalization(x, pop_mean, pop_var, beta, scale, epsilon, name='batch_norm')
  
      return tf.cond(training, batch_statistics, population_statistics)
  </code></pre>
  
  <p>batchnorm3</p>
  
  <pre><code>def batch_norm3(self, x, size, training, decay=0.999):
      beta = tf.Variable(tf.zeros([size]), name='beta')
      scale = tf.Variable(tf.ones([size]), name='scale')
      pop_mean = tf.Variable(tf.zeros([size]), 'mean')
      pop_var = tf.Variable(tf.ones([size]), 'var')
      epsilon = 1e-3
      batch_mean, batch_var = tf.nn.moments(x, [0, 1, 2])
      train_mean = tf.assign(pop_mean, pop_mean * decay + batch_mean * (1 - decay))
      train_var = tf.assign(pop_var, pop_var * decay + batch_var * (1 - decay))
      with tf.control_dependencies([train_mean, train_var]):
          return tf.nn.batch_normalization(x, batch_mean, batch_var, beta, scale, epsilon, name='batch_norm')
  </code></pre>
  
  <p>The only difference between these two definitions is that I remove the <code>tf.cond</code> in <code>batchnorm2</code>, and directly use the <code>True</code> branch of the <code>tf.cond</code> in <code>batchnorm3</code>. In <code>batchnorm3</code>, in fact the <code>train</code> variable is not used, so whatever its type I set, either <code>train=True</code> or <code>train = tf.cast((True), tf.bool)</code>, the error is exactly the same.</p>
  
  <p>The full error message is as follows:</p>
  
  <pre><code>File "some_src_file.py", line 237, in functionA
      grads_vars[i] = (tf.clip_by_norm(grad, mc.MAX_GRAD_NORM), var)
    File "/my_path/local/lib/python2.7/site-packages/tensorflow/python/ops/clip_ops.py", line 110, in clip_by_norm
      t = ops.convert_to_tensor(t, name="t")
    File "/my_path/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 946, in convert_to_tensor
      as_ref=False)
    File "/my_path/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1036, in internal_convert_to_tensor
      ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
    File "/my_path/local/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 235, in _constant_tensor_conversion_function
      return constant(v, dtype=dtype, name=name)
    File "/my_path/local/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 214, in constant
      value, dtype=dtype, shape=shape, verify_shape=verify_shape))
    File "/my_path/local/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 421, in make_tensor_proto
      raise ValueError("None values not supported.")
  ValueError: None values not supported.
  </code></pre>
  
  <p>What is the reason for this? Thank you all for helping me!</p>