예제 #1
0
def yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold=.6):
    """Filter YOLO boxes based on object and class confidence."""
    box_scores = box_confidence * box_class_probs
    box_classes = K.argmax(box_scores, axis=-1)
    box_class_scores = K.max(box_scores, axis=-1)
    prediction_mask = box_class_scores >= threshold

    # TODO: Expose tf.boolean_mask to Keras backend?
    boxes = tf.boolean_mask(boxes, prediction_mask)
    scores = tf.boolean_mask(box_class_scores, prediction_mask)
    classes = tf.boolean_mask(box_classes, prediction_mask)
    return boxes, scores, classes
예제 #2
0
def softmax(x):
    ndim = K.ndim(x)
    if ndim == 2:
        return K.softmax(x)
    elif ndim == 3:
        e = K.exp(x - K.max(x, axis=-1, keepdims=True))
        s = K.sum(e, axis=-1, keepdims=True)
        return e / s
    else:
        raise ValueError('Cannot apply softmax to a tensor '
                         'that is not 2D or 3D. '
                         'Here, ndim=' + str(ndim))
예제 #3
0
파일: activations.py 프로젝트: lengjia/RRL
def softmax(x, axis=-1):
    """Softmax activation function.

  Arguments:
      x : Tensor.
      axis: Integer, axis along which the softmax normalization is applied.

  Returns:
      Tensor, output of softmax transformation.

  Raises:
      ValueError: In case `dim(x) == 1`.
  """
    ndim = K.ndim(x)
    if ndim == 2:
        return K.softmax(x)
    elif ndim > 2:
        e = K.exp(x - K.max(x, axis=axis, keepdims=True))
        s = K.sum(e, axis=axis, keepdims=True)
        return e / s
    else:
        raise ValueError('Cannot apply softmax to a tensor that is 1D')
예제 #4
0
def softmax(x, axis=-1):
  """Softmax activation function.

  Arguments:
      x : Tensor.
      axis: Integer, axis along which the softmax normalization is applied.

  Returns:
      Tensor, output of softmax transformation.

  Raises:
      ValueError: In case `dim(x) == 1`.
  """
  ndim = K.ndim(x)
  if ndim == 2:
    return K.softmax(x)
  elif ndim > 2:
    e = K.exp(x - K.max(x, axis=axis, keepdims=True))
    s = K.sum(e, axis=axis, keepdims=True)
    return e / s
  else:
    raise ValueError('Cannot apply softmax to a tensor that is 1D')
예제 #5
0
파일: metrics.py 프로젝트: lengjia/RRL
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
    return K.mean(K.in_top_k(y_pred, K.cast(K.max(y_true, axis=-1), 'int32'),
                             k),
                  axis=-1)
예제 #6
0
파일: metrics.py 프로젝트: lengjia/RRL
def sparse_categorical_accuracy(y_true, y_pred):
    return K.cast(
        K.equal(K.max(y_true, axis=-1),
                K.cast(K.argmax(y_pred, axis=-1), K.floatx())), K.floatx())
예제 #7
0
 def call(self, inputs):
   if self.data_format == 'channels_last':
     return K.max(inputs, axis=[1, 2, 3])
   else:
     return K.max(inputs, axis=[2, 3, 4])
예제 #8
0
 def call(self, inputs):
   return K.max(inputs, axis=1)
예제 #9
0
 def call(self, inputs):
   if self.data_format == 'channels_last':
     return K.max(inputs, axis=[1, 2, 3])
   else:
     return K.max(inputs, axis=[2, 3, 4])
예제 #10
0
 def call(self, inputs):
   return K.max(inputs, axis=1)
예제 #11
0
def sparse_categorical_accuracy(y_true, y_pred):
  return K.equal(
      K.max(y_true, axis=-1), K.cast(K.argmax(y_pred, axis=-1), K.floatx()))
예제 #12
0
파일: losses.py 프로젝트: zxypat/tensorflow
def categorical_hinge(y_true, y_pred):
    pos = K.sum(y_true * y_pred, axis=-1)
    neg = K.max((1. - y_true) * y_pred, axis=-1)
    return K.maximum(neg - pos + 1., 0.)
예제 #13
0
def categorical_hinge(y_true, y_pred):
  pos = K.sum(y_true * y_pred, axis=-1)
  neg = K.max((1. - y_true) * y_pred, axis=-1)
  return K.maximum(neg - pos + 1., 0.)
예제 #14
0
파일: metrics.py 프로젝트: Dr4KK/tensorflow
def sparse_top_k_categorical_accuracy(y_true, y_pred, k=5):
  return K.mean(K.in_top_k(y_pred,
                           K.cast(K.max(y_true, axis=-1), 'int32'), k), axis=-1)