defined loss function in tensorflow? -
in project, negative instance far more positive instance, want give positive instance larger weight. target is:
loss = 0.0 if y_label==1:loss += 100 * cross_entropy else:loss += cross_entropy
how realizate in tensorflow[?]
let losses
vector (rank-1 tensor) of loss values examples in batch. , let y
the vector of corresponding labels. achieve result want by
weights = w_pos*y + w_neg*(1.0-y) loss = tf.reduce_mean(weights*losses)
here, w_pos
, w_neg
constant scalar values (w_pos=100.0
, w_neg=1.0
in example). vector weights
has value of w_pos
examples label equals 1 , w_neg
equals 0. multiply weights
element-wise losses
weigh values in losses
according corresponding labels , take mean.
Comments
Post a Comment