全连接网络实现mnist
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import datasets
import matplotlib
from matplotlib import pyplot as plt
def preprocess(x, y):
x = tf.cast(x, dtype=tf.float32) / 255.
x = tf.reshape(x, [-1, 28 * 28])
y = tf.cast(y, dtype=tf.int32)
y = tf.one_hot(y, depth=10)
return x, y;
(x, y), (x_test, y_test) = datasets.mnist.load_data()
print('x:', x.shape, 'y:', y.shape, 'x test:', x_test.shape, 'y test:', y_test)
batchsz = 128
train_db = tf.data.Dataset.from_tensor_slices((x, y))
train_db