标签:log tac import oct 5.5 def flow utf-8 tensor
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 2 08:43:02 2018
@author: myhaspl
@email:myhaspl@myhaspl.com
tf.nn.softmax
tf.nn.sparse_softmax_cross_entropy_with_logits
tf.nn.softmax_cross_entropy_with_logits
"""
import tensorflow as tf
g=tf.Graph()
with g.as_default():
x1=tf.constant([0.4,0.2,0.9,0.81])
x2=tf.constant([0.6,0.3,0.7,0.6])
x3=tf.constant([0.7,0.4,0.8,0.95])
y1=[tf.nn.softmax(x1)]
y2=tf.nn.softmax(x2)
y3=tf.nn.softmax(x3)
y=tf.stack([y2,y3])
labels1 = [0,2]
logits1 = [2,0.5]
labels2 = [1,3]
logits2 = [[2,0.5,6,2,1],[1.8,0.3,2,0.1,0.5]]
result1 = tf.nn.softmax_cross_entropy_with_logits(labels=labels1, logits=logits1)
result2 = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels2, logits=logits2)
with tf.Session(graph=g) as sess:
print sess.run(result1)
print sess.run(result2)
3.4028268
[5.5463643 2.7646239]
tf.nn.sparse_softmax_cross_entropy_with_logits表示一个样本只能属于一类,具有排他性。但要注意,labels是稀疏表示的,是 [0,num_classes]中的一个数值,因此,labels的每个元素是标量标签值,对应着logits中的向量输出值。
tf.nn.softmax_cross_entropy_with_logits表示一个样本可以属于多类,不具排他性。labels和logits为正常的单个或多个向量标签值与输出值。
tensorflow-tf.nn.softmax,tf.nn.sparse_softmax_cr
标签:log tac import oct 5.5 def flow utf-8 tensor
原文地址:http://blog.51cto.com/13959448/2325556