title: How to use tensorflow tf.metrics.mean_iou?
body: <p>I am trying to use the inbuilt mean_iou function of tensorflow to compute the IoU score for semantic segmentation. </p>
  
  <p>My code is: </p>
  
  <pre><code>#y_mask.shape == [batch_size, h * w, n_classes]
  #y_mask.shape == [batch_size, h * w, n_classes]
  iou = tf.metrics.mean_iou(tf.argmax(y_mask,2), tf.argmax(mask_,2), n_classes)
  </code></pre>
  
  <p>However I am getting the following error trace:</p>
  
  <pre><code>tensorflow.python.framework.errors_impl.FailedPreconditionError: 
  
  Attempting to use uninitialized value mean_iou/total_confusion
  _matrix
           [[Node: mean_iou/AssignAdd = AssignAdd[T=DT_DOUBLE, _class=["loc:@mean_iou/total_confusion_matrix"], use_locking=false
  , _device="/job:localhost/replica:0/task:0/cpu:0"](mean_iou/total_confusion_matrix, mean_iou/confusion_matrix/SparseTensorDense
  Add)]]
  
  Caused by op u'mean_iou/AssignAdd', defined at:
    File "sample_tf_ynet.py", line 207, in &lt;module&gt;
      trainSeg()
    File "sample_tf_ynet.py", line 166, in trainSeg
      iou, cm_op = tf.metrics.mean_iou(tf.argmax(y_mask,2), tf.argmax(mask_,2), n_classes)
    File "/home/meetshah1995/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/metrics_impl.py", line 782, in mean_iou
      update_op = state_ops.assign_add(total_cm, current_cm)
    File "/home/meetshah1995/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_state_ops.py", line 75, in assign_ad
  d
      use_locking=use_locking, name=name)
    File "/home/meetshah1995/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in a
  pply_op
      op_def=op_def)
    File "/home/meetshah1995/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2395, in create_op
      original_op=self._default_original_op, op_def=op_def)
    File "/home/meetshah1995/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1264, in __init__
      self._traceback = _extract_stack()
  
  FailedPreconditionError (see above for traceback): Attempting to use uninitialized value mean_iou/total_confusion_matrix
           [[Node: mean_iou/AssignAdd = AssignAdd[T=DT_DOUBLE, _class=["loc:@mean_iou/total_confusion_matrix"], use_locking=false
  , _device="/job:localhost/replica:0/task:0/cpu:0"](mean_iou/total_confusion_matrix, mean_iou/confusion_matrix/SparseTensorDense
  Add)]]
  </code></pre>
  
  <p>Please guide me on the correct usage of this for semantic segmentation.</p>