tensorflow
为什么它训练了一点然后报错数据维度不对,要四维我给的是三维。可如果数据不对前几个怎么会训练呢?
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, 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, epochs=30, validation_data=(test_images,test_labels))
还有为什么我expand_dim之后数据量变成1万了,原来是6万。。教程好像没有变
tensorflow版本2.5-GPU 训练一个周期后报错,说明是valid的纬度不对。 第7行错了 train_images = tf.expand_dims(test_images,-1) 又是train又是test一定有问题
页:
[1]