[英]problem with training model from mnist in tensorflow and keras
this is my code:这是我的代码:
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);
show me this error:告诉我这个错误:
---------------------------------------------------------------------------
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).
probably this is enough:可能这就足够了:
train.repeat().batch(batch_size)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.