-*- coding: utf-8 -*-
"""
Created on Sat Oct 28 15:40:51 2017
@author: Administrator
"""
import tensorflow as tf
from tensorflow.python import debug as tf_debug
'''载入数据'''
from aamodule import input_data
mnist = input_data.read_data_sets('d://MNIST',one_hot=True)
'''构建回归模型'''
#定义回归模型
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]))
y_ = tf.matmul(x,W) + b #预测值
#定义损失函数和优化器
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=y_,labels=y)
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
'''训练模型'''
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
sess = tf_debug.LocalCLIDebugWrapperSession(sess,ui_type='readline')
#sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
#Train
for i in range(1000):
batch_xs,batch_ys = mnist.train.next_batch(100)
sess.run(train_step,feed_dict={x:batch_xs,y:batch_ys})
#评估训练好的模型
correct_prediction = tf.equal(tf.argmax(y_,1),tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
#计算模型在测试集上的准确率
print(sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels}))
加入sess = tf_debug.LocalCLIDebugWrapperSession(sess,ui_type='readline')后就运行不了了,ValueError: Exhausted all fallback ui_types.