Esempio n. 1
0
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
    # If the shape of y_true is (num_samples, 1), squeeze to (num_samples,)
    if (len(K.int_shape(y_true)) == len(K.int_shape(y_pred))):
        y_true = array_ops.squeeze(y_true, [-1])

    return K.mean(nn.in_top_k(y_pred, math_ops.cast(y_true, 'int32'), k),
                  axis=-1)
Esempio n. 2
0
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
  # If the shape of y_true is (num_samples, 1), squeeze to (num_samples,)
  if (len(K.int_shape(y_true)) == len(K.int_shape(y_pred))):
    y_true = array_ops.squeeze(y_true, [-1])

  return K.mean(nn.in_top_k(y_pred, math_ops.cast(y_true, 'int32'), k), axis=-1)
Esempio n. 3
0
def top_k_categorical_accuracy(y_true, y_pred, k=5):
  return K.mean(
      nn.in_top_k(y_pred, math_ops.argmax(y_true, axis=-1), k), axis=-1)
Esempio n. 4
0
 def _top_k(probabilities, targets):
     targets = math_ops.to_int32(targets)
     if targets.get_shape().ndims > 1:
         targets = array_ops.squeeze(targets, squeeze_dims=[1])
     return metric_ops.streaming_mean(nn.in_top_k(probabilities, targets,
                                                  k))
Esempio n. 5
0
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
  return K.mean(
      nn.in_top_k(y_pred,
                  math_ops.cast(math_ops.reduce_max(y_true, axis=-1), 'int32'),
                  k),
      axis=-1)
Esempio n. 6
0
def top_k_categorical_accuracy(y_true, y_pred, k=5):
    return K.mean(nn.in_top_k(y_pred, math_ops.argmax(y_true, axis=-1), k),
                  axis=-1)
Esempio n. 7
0
 def _top_k(probabilities, targets):
   targets = math_ops.to_int32(targets)
   if targets.get_shape().ndims > 1:
     targets = array_ops.squeeze(targets, squeeze_dims=[1])
   return metric_ops.streaming_mean(nn.in_top_k(probabilities, targets, k))
Esempio n. 8
0
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
    return K.mean(nn.in_top_k(
        y_pred, math_ops.cast(math_ops.reduce_max(y_true, axis=-1), 'int32'),
        k),
                  axis=-1)
Esempio n. 9
0
 def _top_k(probabilities, targets):
     return metric_ops.streaming_mean(
         nn.in_top_k(probabilities, math_ops.to_int32(targets), k))
Esempio n. 10
0
 def _top_k(probabilities, targets):
   targets = math_ops.cast(targets, dtypes.int32)
   if targets.get_shape().ndims > 1:
     targets = array_ops.squeeze(targets, axis=[1])
   return metrics.mean(nn.in_top_k(probabilities, targets, k))
Esempio n. 11
0
 def _top_k(probabilities, targets):
   return metric_ops.streaming_mean(nn.in_top_k(probabilities,
                                                math_ops.to_int32(targets), k))
Esempio n. 12
0
 def _top_k(probabilities, targets):
     targets = math_ops.cast(targets, dtypes.int32)
     if targets.get_shape().ndims > 1:
         targets = array_ops.squeeze(targets, axis=[1])
     return metrics.mean(nn.in_top_k(probabilities, targets, k))
Esempio n. 13
0
 def model(a, b):
     return nn.in_top_k(a, b, topn)