import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
(train_image, train_label),(test_image,test_label) = tf.keras.datasets.fashion_mnist.load_data()
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
loss='categorical_crossentropy',
metrics=['acc'])
plt.imshow(train_image[0])
train_image[0]
#数据归一化
train_image = train_image/255
test_image = test_image/255
#独热编码
train_label_onehot = tf.keras.utils.to_categorical(train_label)
test_label_onehot = tf.keras.utils.to_categorical(test_label)
#模型初始化并添加层
model = tf.keras.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28,28)))
model.add(tf.keras.layers.Dense(128, activation='relu'))
model.add(tf.keras.layers.Dense(128, activation='relu'))
model.add(tf.keras.layers.Dense(128, activation='relu'))
model.add(tf.keras.lay
学习笔记||tensorflow-过拟合及解决
最新推荐文章于 2023-08-25 18:03:45 发布