Я запускаю свой код в spyder
, перекрестная энтропия набора тестов верна, но точность набора тестов всегда очень низкая.Это мой кодЯ пользуюсь мнистом.Любой совет, как я могу улучшить производительность?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import tensorflow as tf
import numpy as np
from tensorflow.contrib.layers import fully_connected
from tensorflow.examples.tutorials.mnist import input_data
x = tf.placeholder(dtype=tf.float32,shape=[None,784])
y = tf.placeholder(dtype=tf.float32,shape=[None,10])
test_x = tf.placeholder(dtype=tf.float32,shape=[None,784])
test_y = tf.placeholder(dtype=tf.float32,shape=[None,10])
mnist = input_data.read_data_sets("/home/xuenzhu/mnist_data", one_hot=True)
hidden1 = fully_connected(x,100,activation_fn=tf.nn.relu,weights_initializer=tf.random_normal_initializer())
hidden2 = fully_connected(hidden1,100,activation_fn=tf.nn.relu,weights_initializer=tf.random_normal_initializer())
outputs = fully_connected(hidden2,10,activation_fn=tf.nn.relu,weights_initializer=tf.random_normal_initializer())
loss = tf.nn.softmax_cross_entropy_with_logits(labels=y,logits=outputs)
reduce_mean_loss = tf.reduce_mean(loss)
equal_result = tf.equal(tf.argmax(outputs,1),tf.argmax(y,1))
cast_result = tf.cast(equal_result,dtype=tf.float32)
accuracy = tf.reduce_mean(cast_result)
train_op = tf.train.AdamOptimizer(0.001).minimize(reduce_mean_loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels}))
for i in range(10000):
xs,ys = mnist.train.next_batch(128)
sess.run(train_op,feed_dict={x:xs,y:ys})
if i%1000==0:
print(sess.run(equal_result,feed_dict={x:mnist.test.images,y:mnist.test.labels}))
print(sess.run(reduce_mean_loss,feed_dict={x:mnist.test.images,y:mnist.test.labels}))[enter image description here][1]
print(sess.run(accuracy,feed_dict={x:mnist.test.images,y:mnist.test.labels}))