为什么它训练了一点然后报错数据维度不对,要四维我给的是三维。
可如果数据不对前几个怎么会训练呢?
[Python] 纯文本查看 复制代码 import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
train_images = tf.expand_dims(test_images,-1)
model = tf.keras.Sequential() # 顺序模型
model.add(tf.keras.layers.Conv2D(32,(3, 3),input_shape=train_images.shape[1:], activation='relu', padding='same')) # 卷积层
model.add(tf.keras.layers.MaxPool2D()) # 默认卷积核2x2
model.add(tf.keras.layers.Conv2D(64,(3, 3), activation='relu'))
model.add(tf.keras.layers.GlobalAveragePooling2D()) # 四维变二维,dense需要二维输入
model.add(tf.keras.layers.Dense(10, activation='softmax')) # 连接层
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['acc'])
history = model.fit(train_images, train_labels[312:10312], epochs=30, validation_data=(test_images,test_labels))
这是报错
还有为什么我expand_dim之后数据量变成1万了,原来是6万。。教程好像没有变
tensorflow版本2.5-GPU |