Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import tensorflow as tf
def object_loss(scores, labels):
with tf.variable_scope('object_loss'):
loss_vector = tf.nn.softmax_cross_entropy_with_logits(
scores,
labels,
name='softmax_cross_entropy_with_logits')
loss = tf.reduce_mean(
loss_vector,
name='average_loss')
return loss
def attribute_loss(scores, labels):
with tf.variable_scope('attribute_loss'):
loss_matrix = tf.nn.sigmoid_cross_entropy_with_logits(
scores,
labels,
name='sigmoid_cross_entropy_with_logits')
# label_count = tf.reduce_mean(
# labels,
# 0,
# keep_dims=True,
# name='label_count')
# label_count = tf.truediv(
# label_count,
# tf.to_float(label_count.get_shape().as_list()[0]),
# name='normalized_label_count')
loss = tf.reduce_mean(
loss_matrix,
# tf.matmul(loss_matrix, tf.transpose(label_count)),
name='average_loss')
return loss
def regularization_loss(param_list, coeff):
regularizer = tf.zeros(shape=[])
for param in param_list:
regularizer += tf.nn.l2_loss(param)
return coeff*regularizer