打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
tensorflow 第八课 saver Iter0,Testing Accuracy 0.9288
import tensorflow as tf
from tensorflow.contrib import rnn
from tensorflow.examples.tutorials.mnist import input_data
#载入数据
mnist = input_data.read_data_sets("/home/mj/MINIST_data", one_hot=True)
#每个批次一百张照片
batch_size=100
#计算一共有多少个批次
n_batch=mnist.train.num_examples

x=tf.placeholder(tf.float32,[None,784])
y=tf.placeholder(tf.float32,[None,10])

w=tf.Variable(tf.zeros([784,10]))
b=tf.Variable(tf.zeros(10))
prediction=tf.nn.softmax(tf.matmul(x,w)+b)

loss=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=y,logits=prediction))

train=tf.train.GradientDescentOptimizer(0.2).minimize(loss)

init=tf.global_variables_initializer()

correct_prediction=tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))
accu=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
saver=tf.train.Saver()
with tf.Session() as sess:
sess.run(init)
for epoch in range(1):
for batch in range(n_batch):
batch_x1,batch_y2=mnist.train.next_batch(batch_size)
sess.run(train,feed_dict={x:batch_x1,y:batch_y2})
acc=sess.run(accu,feed_dict={x:mnist.test.images,y:mnist.test.labels})
print("Iter"+str(epoch)+",Testing Accuracy "+str(acc))
saver.save(sess,'model/2018_8_14.ckpt')
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
学习TensorFlow,保存学习到的网络结构参数并调用
【机器学习】DNN训练中的问题与方法
Tensorflow如何导出与使用预测图
Tensorflow实例:利用LSTM预测股票每日最高价(二)
手把手教TensorFlow(附代码)
将Keras作为tensorflow的精简接口
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服