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]

时间: 2024-08-13 22:14:02

tensorflow softmax应用的相关文章

学习笔记TF024:TensorFlow实现Softmax Regression(回归)识别手写数字

TensorFlow实现Softmax Regression(回归)识别手写数字.MNIST(Mixed National Institute of Standards and Technology database),简单机器视觉数据集,28X28像素手写数字,只有灰度值信息,空白部分为0,笔迹根据颜色深浅取[0, 1], 784维,丢弃二维空间信息,目标分0~9共10类.数据加载,data.read_data_sets, 55000个样本,测试集10000样本,验证集5000样本.样本标注信

Softmax回归(使用tensorflow)

1 # coding:utf8 2 import numpy as np 3 import cPickle 4 import os 5 import tensorflow as tf 6 7 class SoftMax: 8 def __init__(self,MAXT=30,step=0.0025): 9 self.MAXT = MAXT 10 self.step = step 11 12 def load_theta(self,datapath="data/softmax.pkl"

TensorFlow 入门之手写识别(MNIST) softmax算法

TensorFlow 入门之手写识别(MNIST) softmax算法 MNIST 卢富毓 softmax回归 softmax回归算法 TensorFlow实现softmax softmax回归算法 我们知道MNIST的每一张图片都表示一个数字,从0到9.我们希望得到给定图片代表每个数字的概率.比如说,我们的模型可能推测一张包含9的图片代表数字9的概率是80%但是判断它是8的概率是5%(因为8和9都有上半部分的小圆),然后给予它代表其他数字的概率更小的值. 这是一个使用softmax回归(sof

tensorflow学习之softmax regression

电脑配置:win10 + Anaconda3 + pyton3.5 + vs2013 + tensorflow + Gpu980 + matlab2016b softmax regression的详细介绍,请参考黄文坚的<tensorflow实战>的第3.2节. 原书pdf下载地址: 链接:https://pan.baidu.com/s/1sk8Qm4X 密码:28jk 原书code下载地址:链接:https://pan.baidu.com/s/1eR1LepW 密码:kmiz 我这里的贡献,

TensorFlow实战之Softmax Regression识别手写数字

     关于本文说明,本人原博客地址位于http://blog.csdn.net/qq_37608890,本文来自笔者于2018年02月21日 23:10:04所撰写内容(http://blog.csdn.net/qq_37608890/article/details/79343860).        本文根据最近学习TensorFlow书籍网络文章的情况,特将一些学习心得做了总结,详情如下.如有不当之处,请各位大拿多多指点,在此谢过. 一.相关概念 1.MNIST MNIST(Mixed

【TensorFlow/简单网络】MNIST数据集-softmax、全连接神经网络,卷积神经网络模型

初学tensorflow,参考了以下几篇博客: soft模型 tensorflow构建全连接神经网络 tensorflow构建卷积神经网络 tensorflow构建卷积神经网络 tensorflow构建CNN[待学习] 全连接+各种优化[待学习] BN层[待学习] 先解释以下MNIST数据集,训练数据集有55,000 条,即X为55,000 * 784的矩阵,那么Y为55,000 * 10的矩阵,每个图片是28像素*28像素,带有标签,Y为该图片的真实数字,即标签,每个图片10个数字,1所在位置

TensorFlow 训练 MNIST (1)—— softmax 单层神经网络

1.MNIST数据集简介 首先通过下面两行代码获取到TensorFlow内置的MNIST数据集: from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets('./data/mnist', one_hot=True) MNIST数据集共有55000(mnist.train.num_examples)张用于训练的数据,对应的有55000个标签:共有10000(mnist.t

TensorFlow实现Softmax回归(模型存储与加载)

1 # -*- coding: utf-8 -*- 2 """ 3 Created on Thu Oct 18 18:02:26 2018 4 5 @author: zhen 6 """ 7 8 from tensorflow.examples.tutorials.mnist import input_data 9 import tensorflow as tf 10 11 # mn.SOURCE_URL = "http://yann.

TensorFlow实现Softmax

我们先来理解理解Softmax:任意事件发生的概率都在 0 和 1 之间,且总有某一个事件发生 (概率的和为 1 ).如果将分类问题中“ 一个样例属于某一个类别”看成一个概率事件, 那么训练数据的正确答案就符合一个概率分布.因为事件“一个样例属于不正确的类别”的概率为0,而“ 一个样例属于正确的类别”的概率为 1.如何将神经网络前向传播得到的结果也变成概率分布呢? Softmax 回归就是一个非常常用的方法 .Softmax 回归本身可以作为 一个学习算法来优化分类结果,但在TensorFlow