tensorflow softmax應用
阿新 • • 發佈:2017-07-21
tput oat put utf 實現 light pre clas out
---恢復內容開始---
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]
tensorflow softmax應用