Yaohong

为了真相不惜被羞辱

Categorical Crossentropy源码分析

Categorical Crossentropy源码分析

Source:

import tensorflow as tf
import numpy as np
sess = tf.InteractiveSession()

print("--------output-----------")
target = tf.constant([1., 0., 0., 0., 1., 0., 0., 0., 1.], shape=[3,3])
print("target: \n",target.eval())

output = tf.constant([.9, .05, .05, .05, .89, .06, .05, .01, .94], shape=[3,3])
print("output:\n ",output.eval())

loss = tf.keras.backend.categorical_crossentropy(target, output)
print("loss: \n",loss.eval()) # Output: [0.10536 0.11653 0.06188]

官方文档categorical_crossentropy

Output:

--------output-----------
target: 
 [[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
output:
  [[0.9  0.05 0.05]
 [0.05 0.89 0.06]
 [0.05 0.01 0.94]]
loss: 
 [0.10536055 0.11653383 0.06187541]

问:输出中最后一行,loss第一个值0.10536055是什么得到的?