python cnn mnist
小白一枚 cnn mnist 不会改呀 可以指点一下吗import numpy as np
import as tf
tf.disable_v2_behavior()
from tensorflow import keras
# down load and load Mnist library(55000 * 28 * 28)
#from tensorflow.keras.datasets.mnist import input_data
mnist=keras.datasets.mnist.load_data('mnist_data')
#mnist = input_data.read_data_sets('mnist_data', one_hot=True)
# 代表训练数据, /255. 的目的是其取值范围在【0,255】
input_x = tf.placeholder(tf.float32, [None, 28 * 28]) / 255.
# 代表的是10个标签,0,1,2,3....9
output_y = tf.placeholder(tf.int32, [None, 10])
# shape 前面使用-1,能够自动的对其形状进行推导
input_x_image = tf.reshape(input_x, [-1, 28, 28, 1])
# 从测试数据集中选取3000个测试数据进行验证模型,
# 每次都使用这一批相同的测试数据进行测试,能够保证唯一性
test_x = mnist.tets.images[:3000] # picture
test_y = mnist.tets.labels[:3000] # label
错误提示
File "C:/Users/16150/Documents/WeChat Files/wxid_0xraduf92ady21/FileStorage/File/2021-09/1.py", line 31, in <module>
test_x = mnist.tets.images[:3000] # picture
AttributeError: 'tuple' object has no attribute 'tets'
for i in range(5000):
# 每次的数据从mnist训练数据集中选取 50 份出来训练
batch = mnist.train.next_batch(50) # get 50 sample
train_loss, train_op_ = sess.run([loss, train_op], {input_x: batch[0], output_y: batch[1]})
还有个错误是'tuple' object has no attribute 'train'