import tensorflow as tf
import numpy as np
from keras.preprocessing import image
import cv2
import matplotlib.pyplot as plt
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
training_images = training_images.reshape(60000, 28, 28, 1)
training_images = training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images = test_images / 255.0
model = tf.keras.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation="relu"),
tf.keras.layers.Dense(10, activation="softmax")
])
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.fit(training_images, training_labels, epochs=20)
我正在关注YouTube上的AI教程。从那里我得到了这段代码。在本教程中,他们使用了Google CoLab,并且一切正常。因此,当我运行代码时,最后一行抛出错误:ValueError: Attempt to convert a value (9) with an unsupported type (<class 'numpy.uint8'>) to a Tensor.
有人知道我错过了什么或如何解决该错误吗?