![](/img/trans.png)
[英]Keras VGG model for MNIST: Disparity between training and validation accuracy
[英]problem with training model from mnist in tensorflow and keras
這是我的代碼:
import tensorflow as tf
import tensorflow_datasets as tfds
import math
import numpy as np
import matplotlib.pyplot as plt
dataset = tfds.load('fashion_mnist', as_supervised=True)
train = dataset['train'];
test = dataset['test'];
def normalize(image, label):
image = tf.cast(image, tf.float32);
image = image/255;
return image, label
train = train.map(normalize);
test = test.map(normalize);
train = train.cache();
test = test.cache();
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(500, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy,
metrics=['accuracy'])
model.fit(train, epochs=10, batch_size=100);
告訴我這個錯誤:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-57-07d41cbbc0f1> in <module>()
----> 1 model.fit(train, epochs=10, batch_size=100);
1 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/data_adapter.py in _validate_args(self, y, sample_weights, steps)
759 if size == tf.data.experimental.INFINITE_CARDINALITY and steps is None:
760 raise ValueError(
--> 761 "When providing an infinite dataset, you must specify "
762 "the number of steps to run (if you did not intend to "
763 "create an infinite dataset, make sure to not call "
ValueError: When providing an infinite dataset, you must specify the number of steps to run (if you did not intend to create an infinite dataset, make sure to not call `repeat()` on the dataset).
可能這就足夠了:
train.repeat().batch(batch_size)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.