tensorflow softmax应用

---恢复内容开始---

1、softmax函数

 

 

 

 

2、tensorflow实现例子

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tensorflow as tf

input_data = tf.Variable( [[0.2, 0.2, 0.2]] , dtype = tf.float32 )
output = tf.nn.softmax(input_data)
with tf.Session() as sess:
    init = tf.initialize_all_variables()
    sess.run(init)
    print(sess.run(input_data))
    print(sess.run(output))
    print(sess.run(tf.shape(output)) )

输出为:

[[ 0.2 0.2 0.2]]
[[ 0.33333334 0.33333334 0.33333334]]
[1 3]

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tensorflow as tf

input_data = tf.Variable( [[0.2, 0.2, 0.2],[1,2,3]] , dtype = tf.float32 )
output = tf.nn.softmax(input_data)
with tf.Session() as sess:
    init = tf.initialize_all_variables()
    sess.run(init)
    print(sess.run(input_data))
    print(sess.run(output))
    print(sess.run(tf.shape(output)) )

  

  输出为:

[[ 0.2 0.2 0.2]
[ 1. 2. 3. ]]
[[ 0.33333334 0.33333334 0.33333334]
[ 0.09003057 0.24472848 0.66524094]]
[2 3]

 

posted @ 2017-07-21 18:12  debuggor  阅读(257)  评论(0编辑  收藏  举报