title: What is y_true and y_pred when creating a custom metric in Keras?
body: <p>I want to implement my custom metric in Keras. According to the documentation, my custom metric should be defined as a function that takes as input two tensors, <code>y_pred</code> and <code>y_true</code>, and returns a single tensor value. </p>
  
  <p>However, I'm confused to what exactly will be contained in these tensors <code>y_pred</code> and <code>y_true</code> when the optimization is running. Is it just one data point? Is it the whole batch? The whole epoch (probably not)? Is there a way to obtain these tensors' shapes?</p>
  
  <p>Can someone point to a trustworthy place where I can get this information? Any help would be appreciated. Not sure if relevant, but I'm using TensorFlow backend.</p>
  
  <hr>
  
  <p>Things I tried so far, in order to answer this:</p>
  
  <ul>
  <li>Checking the <a href="https://keras.io/metrics/" rel="noreferrer">Keras metrics documentation</a> (no explanation there about what these tensors are).</li>
  <li>Checking the <a href="https://github.com/fchollet/keras/blob/master/keras/metrics.py" rel="noreferrer">source code for the Keras metrics</a> and trying to understand these tensors by looking at the Keras implementation for other metrics (This seems to suggest that <code>y_true</code> and <code>y_pred</code> have the labels for an entire batch, but I'm not sure).</li>
  <li>Reading these stackoverflow questions: <a href="https://stackoverflow.com/questions/45961428/make-a-custom-loss-function-in-keras">1</a>, <a href="https://stackoverflow.com/questions/41458859/keras-custom-metric-for-single-class-accuracy">2</a>, <a href="https://stackoverflow.com/questions/43576922/keras-custom-metric-iteration">3</a>, and others (none answer my question, most are centered on the OP not clearly understanding the difference between a tensor and the values computed using that tensor during the session).</li>
  <li>Printing the values of <code>y_true</code> and <code>y_pred</code> during the optimization, by defining a metric like this:</li>
  </ul>
  
  
  
  <pre class="lang-py prettyprint-override"><code>    def test_metric(y_true, y_pred):
          y_true = K.print_tensor(y_true)
          y_pred = K.print_tensor(y_pred)
          return y_true - y_pred
  </code></pre>
  
  <p>(unfortunately these don't print anything during the optimization).</p>