title: Issue with custom metric auc callback for keras
body: <p>I am trying to implement custom <code>roccallback</code> for keras. The call back function I wrote is below. I have to achieve a target of 0.90.</p>
  <p><strong>AUROC callback:</strong></p>
  <pre><code>class rocback(Callback):
    def __init__(self, validation_data):
      super(rocback, self).__init__()
      # self.training_data = training_data
      self.validation_data = validation_data
  
    def on_train_begin(self, logs={}) :
      return
  
    def on_epoch_end(self, epoch, logs={}):
      probs = self.model.predict(self.validation_data[0])
      probs = np.round(probs)
      y_true = self.validation_data[1]
      y_true = np.round(y_true)
      score = roc_auc_score(y_true, probs, average='micro')
      logs['auc'] = score
  </code></pre>
  <p>Hence next callback which I wrote was to achieve the target.</p>
  <pre><code>class scoreTarget(Callback):
    def __init__(self, target):
      super(scoreTarget, self).__init__()
      self.target = target
  
    def on_epoch_end(self, epoch, logs={}):
      acc = logs['auc']
      if acc &gt;= self.target:
        self.model.stop_training = True
  </code></pre>
  <p>The list of call back used is below:</p>
  <pre><code>roc_callback   = rocback((X_test_pooled_output, y_test))
  early_stopping = EarlyStopping(patience=5)
  tensorboard    = TensorBoard()
  reduce_lr      = ReduceLROnPlateau(patience=3)
  target         = scoreTarget(0.90)
  
  callbacks = [
        roc_callback,
        early_stopping,
        tensorboard,
        reduce_lr,
        target,
  ]
  </code></pre>
  <p>The classifier function which I wrote is below:</p>
  <pre><code>class ReviewClassifier(Model):
    def __init__(self):
      super(ReviewClassifier, self).__init__()
      self.dense_1 = Dense(64, activation='relu')
      self.dense_2 = Dense(32, activation='relu')
      self.dense_3 = Dense(16, activation='relu')
      self.classify = Dense(1, activation='sigmoid')
      self.dropout_1 = Dropout(0.2)
      self.dropout_2 = Dropout(0.2)
      self.dropout_3 = Dropout(0.2)
  
    def call(self, inputs):
      x = self.dense_1(inputs)
      x = self.dropout_1(x)
      x = self.dense_2(x)
      x = self.dropout_2(x)
      x = self.dense_3(x)
      x = self.dropout_3(x)
      x = self.classify(x)
      return x
  
  review_classifier = ReviewClassifier()
  review_classifier.build((None, 768))
  review_classifier.summary()
  </code></pre>
  <p>The compile funtcion I wrote is this:</p>
  <pre><code>review_classifier.compile(loss='binary_crossentropy',
                            optimizer='adam',metrics=[rocback])
  </code></pre>
  <p>fit function:</p>
  <pre><code>!rm -rf ./logs/*
  history = review_classifier.fit(X_train_pooled_output, y_train,
                              batch_size=32, epochs=100,
                              callbacks=callbacks, 
                              validation_data=(X_test_pooled_output, y_test))
  </code></pre>
  <p>The error received is:</p>
  <pre><code>Epoch 1/100
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-54-fd7595a2c88c&gt; in &lt;module&gt;()
        1 get_ipython().system('rm -rf ./logs/*')
  ----&gt; 2 history = review_classifier.fit(X_train_pooled_output, y_train, batch_size=32, epochs=100,callbacks=callbacks, validation_data=(X_test_pooled_output, y_test))
  
  9 frames
  /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
      975           except Exception as e:  # pylint:disable=broad-except
      976             if hasattr(e, &quot;ag_error_metadata&quot;):
  --&gt; 977               raise e.ag_error_metadata.to_exception(e)
      978             else:
      979               raise
  
  TypeError: in user code:
  
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:805 train_function  *
          return step_function(self, iterator)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:795 step_function  **
          outputs = model.distribute_strategy.run(run_step, args=(data,))
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
          return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
          return self._call_for_each_replica(fn, args, kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
          return fn(*args, **kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:788 run_step  **
          outputs = model.train_step(data)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:758 train_step
          self.compiled_metrics.update_state(y, y_pred, sample_weight)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/compile_utils.py:408 update_state
          metric_obj.update_state(y_t, y_p, sample_weight=mask)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/utils/metrics_utils.py:90 decorated
          update_op = update_state_fn(*args, **kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/metrics.py:177 update_state_fn
          return ag_update_state(*args, **kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/metrics.py:618 update_state  **
          matches = ag_fn(y_true, y_pred, **self._fn_kwargs)
  
      TypeError: __init__() takes 2 positional arguments but 3 were given
  </code></pre>
  <p>Any idea what am I doing wrong in the custom callback which I created for roc?</p>
  <p>Let me know what more inputs you need.</p>