ContrastiveLossLayer

ContrastiveLossLayer[]

represents a loss layer that computes a loss based on a distance metric and a target that specifies whether the distance should be minimized or maximized.

ContrastiveLossLayer[margin]

specifies a distance above which the loss is zero for True targets.

Details and Options

Examples

open all close all

Basic Examples  (2)

Create a ContrastiveLossLayer with a given margin:

In[1]:=
Click for copyable input
Out[1]=

Create a ContrastiveLossLayer:

In[1]:=
Click for copyable input
Out[1]=

Apply it to some data:

In[2]:=
Click for copyable input
Out[2]=

If the target is True, the loss is nonzero only when the input distance is less than the default margin of 0.5:

In[3]:=
Click for copyable input
Out[3]=
Out[3]=

If the target is False, the loss is proportional to the input distance:

In[4]:=
Click for copyable input
Out[4]=

Applications  (1)

Introduced in 2017
(11.1)