loss_triplet_hard: Triplet hard loss

Description Usage Arguments Value Examples

View source: R/losses.R

Description

Computes the triplet loss with hard negative and hard positive mining.

Usage

1
loss_triplet_hard(margin = 1, soft = FALSE, name = NULL, ...)

Arguments

margin

Float, margin term in the loss definition. Default value is 1.0.

soft

Boolean, if set, use the soft margin version. Default value is False.

name

Optional name for the op.

...

additional arguments to pass

Value

triplet_loss: float scalar with dtype of y_pred.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
model = keras_model_sequential() %>%
  layer_conv_2d(filters = 64, kernel_size = 2, padding='same', input_shape=c(28,28,1)) %>%
  layer_max_pooling_2d(pool_size=2) %>%
  layer_flatten() %>%
  layer_dense(256, activation= NULL) %>%
  layer_lambda(f = function(x) tf$math$l2_normalize(x, axis = 1L))

model %>% compile(
  optimizer = optimizer_lazy_adam(),
  # apply triplet semihard loss
  loss = loss_triplet_hard())

## End(Not run)

tfaddons documentation built on July 2, 2020, 2:12 a.m.