я хочу выучить модель для глубокой учебы без кераса.
Я должен получить точность более 87% ~
Итак, я попробовал несколько раз, но получил точность 82%.
что мне делать?
Я думаю, что мне нужно добавить скрытый слой больше. но я не знаю как.
пожалуйста, дайте мне знать :)
Огромное спасибо заранее.
(извините за массовые коды)
import numpy as np
import random
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn.metrics import classification_report
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data/',
source_url='http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/',
one_hot=True)
print("Training set (images): {shape}".format(shape=mnist.train.images.shape))
print("Training set (labels): {shape}".format(shape=mnist.train.labels.shape))
print("Test set (images): {shape}".format(shape=mnist.test.images.shape))
print("Test set (labels): {shape}".format(shape=mnist.test.labels.shape))
label_names = [
'T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt',
'Sneaker','Bag', 'Ankle boot' ]
# get 28 by 28 image
sample_1 = mnist.train.images[47].reshape(28, 28)
# get corresponding integer label from one-hot encoded data
sample_label_1 = np.where(mnist.train.labels[47] == 1)[0][0]
# plot sample
print("y = {label_index} ({label})".format(label_index=sample_label_1, label=label_names[sample_label_1]))
plt.imshow(sample_1, cmap='Greys')
#input place holders
X = tf.placeholder(dtype=tf.float32, shape=[None, 784])
Y = tf.placeholder(dtype=tf.float32, shape=[None, 10])
# weights and biases
W = tf.Variable(tf.random_normal([784, 10]))
b = tf.Variable(tf.random_normal([10]))
S = tf.matmul(X, W) + b
hypothesis = S
loss = tf.reduce_mean( tf.nn.softmax_cross_entropy_with_logits_v2(logits=hypothesis, labels=Y))
corrects = tf.equal(tf.argmax(hypothesis, axis=1), tf.argmax(Y, axis=1))
accuracy = tf.reduce_mean(tf.cast(corrects, tf.float32))
LEARNING_RATE = 0.001
EPOCHS =50
BATCH_SIZE=100
optimizer = tf.train.AdamOptimizer(LEARNING_RATE).minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(EPOCHS):
for _ in range(int(mnist.train.num_examples / BATCH_SIZE)):
X_batch, Y_batch = mnist.train.next_batch(BATCH_SIZE)
sess.run(optimizer, feed_dict={X: X_batch, Y: Y_batch})
if (epoch+1) % 1 == 0:
acc_val = sess.run(accuracy, feed_dict={X: mnist.test.images, Y:
mnist.test.labels})
print("epoch: {:04d}, accuracy: {:.2f}".format(epoch+1, acc_val))
print("Learning finished.")