tensorflow_softmax模型
2016-07-29 00:00
169 查看
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """A very simple MNIST classifier. See extensive documentation at http://tensorflow.org/tutorials/mnist/beginners/index.md """ from __future__ import absolute_import from __future__ import division from __future__ import print_function # Import data from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf flags = tf.app.flags FLAGS = flags.FLAGS flags.DEFINE_string('data_dir', '/tmp/data/', 'Directory for storing data') mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True) sess = tf.InteractiveSession() # Create the model x = tf.placeholder(tf.float32, [None, 784]) W = tf.Variable(tf.zeros([784, 10])) b = tf.Variable(tf.zeros([10])) y = tf.nn.softmax(tf.matmul(x, W) + b) # Define loss and optimizer y_ = tf.placeholder(tf.float32, [None, 10]) cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1])) train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) # Train tf.initialize_all_variables().run() for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) train_step.run({x: batch_xs, y_: batch_ys}) # Test trained model correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) print(accuracy.eval({x: mnist.test.images, y_: mnist.test.labels}))
相关文章推荐
- tensorflow程序-最简单softmax模型
- tensorflow学习-示例1(MNIST数据集合上的softmax分类模型)
- TensorFlow学习Day3读取csv文件,动手写个logistic,softmax分类模型
- Tensorflow简单复现softmax模型对于mnist数据集分类
- TensorFlow 实现Softmax 回归模型
- MINST-Tensorflow1.0下搭建softmax模型
- 81、Tensorflow实现LeNet-5模型,多层卷积层,识别mnist数据集
- 基于tensorflow和mnist的LeNet-5模型实现
- tensorflow学习之cifar_10模型评估
- tensorflow实现逻辑回归模型
- LSTM 递归神经网络 基本结构 及 TensorFlow 示例模型介绍
- 将TensorFlow模型变为pb——官方本身提供API,直接调用即可
- TensorFlow实现Softmax
- 如何使用TensorFlow和VAE模型生成手写数字
- 131、TensorFlow保存模型
- Tensorflow实例:Inception-v3模型
- windows下tensorflow两种加载模型的测试数据方法
- 解决学习tensorflow的LSTM模型中遇到一个版本不兼容问题
- TensorFlow教程03:针对机器学习初学者的MNIST实验——回归的实现、训练和模型评估
- [TensorFlow]入门学习笔记(4)-BasicModel 线性回归,逻辑回归和最近邻模型