import tensorflow
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
class Normal:
weight = []
biases = []
def __init__(self):
self.times = 1000
self.mnist = []
self.session = tensorflow.Session()
self.xs = tensorflow.placeholder(tensorflow.float32, [None, 784])
self.ys = tensorflow.placeholder(tensorflow.float32, [None, 10])
self.save_path = 'learn/result/normal.ckpt'
def run(self):
self.import_data()
self.train()
self.save()
def _setWeight(self,weight):
self.weight = weight
def _setBiases(self,biases):
self.biases = biases
def _getWeight(self):
return self.weight
def _getBiases(self):
return self.biases
def train(self):
prediction = self.add_layer(self.xs, 784, 10, activation_function=tensorflow.nn.softmax)
cross_entropy = tensorflow.reduce_mean(
-tensorflow.reduce_sum(
self.ys * tensorflow.log(prediction)
, reduction_indices=[1])
)
train_step = tensorflow.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
self.session.run(tensorflow.global_variables_initializer())
for i in range(self.times):
batch_xs, batch_ys = self.mnist.train.next_batch(100)
self.session.run(train_step, feed_dict={self.xs: batch_xs, self.ys: batch_ys})
if i % 50 ==