def multi_label_ACE(outputs,y_labels):
data_shape=outputs.shape
loss_buff=0
# num=T.iscalar(data_shape[0]) #theano int to get value from tensor
# for i in range(int(num)):
# for j in range(12):
# y_exp=outputs[i,j]
# y_tru=y_labels[i,0,0,j]
# if y_tru==0:
# loss_ij=math.log(1-outputs[i,j])
# loss_buff-=loss_ij
# if y_tru>0:
# loss_ij=math.log(outputs[i,j])
# loss_buff-=loss_ij
# wts=[ 0.24331649, 0.18382575, 0.23082499, 0.44545567, 0.52901483, 0.58482504, \
# 0.57321465, 0.43411294, 0.15502839, 0.36377019, 0.19050646, 0.16083916]
# for i in [3,4,5,6,7,9]:
for i in range(12):
target=y_labels[:,i]
output=outputs[:,i]
loss_au=T.sum(-(target * T.log((output+0.05)/1.05) + (1.0 - target) * T.log((1.05 - output)/1.05)))
loss_buff+=loss_au
return loss_buff/(12*BATCH_SIZE)
评论列表
文章目录