code: def contingency_table(y, z):
      
      y = K.cast(K.round(y), K.floatx())
      z = K.cast(K.round(z), K.floatx())
  
      def count_matches(y, z):
          return K.sum(K.cast(y, K.floatx()) * K.cast(z, K.floatx()))
  
      ones = K.ones_like(y)
      zeros = K.zeros_like(y)
      y_ones = K.equal(y, ones)
      y_zeros = K.equal(y, zeros)
      z_ones = K.equal(z, ones)
      z_zeros = K.equal(z, zeros)
  
      tp = count_matches(y_ones, z_ones)
      tn = count_matches(y_zeros, z_zeros)
      fp = count_matches(y_zeros, z_ones)
      fn = count_matches(y_ones, z_zeros)
  
      return (tp, tn, fp, fn)
docs: Note:  if y and z are not rounded to 0 or 1, they are ignored