python - 图像识别 ANN 给出 InvalidArgumentError
问题描述
我是 tensorflow 的新手,我收到以下错误InvalidArgumentError: Received a label value of 10 which is outside the valid range of [0, 10). Label values: 6 6 1 3 8 9 1 1 7 9 2 9 3 3 6 4 7 1 1 5 4 1 7 1 3 3 8 6 10 4 10 2
,但我不知道我做错了什么?
该数据集是具有 32 x 32 图像和 3 个颜色通道的图像识别数据集。我正在尝试使用标准 ANN
# Shape info
# x train shape : (73257, 32, 32, 3)
# y train shape : (73257,)
# 10 categorical variables
def getModel(input_shape):
model = Sequential([
Flatten(input_shape = input_shape),
Dense(32,activation = "relu", name = "layer1"),
Dense(32,activation = "relu", name = "layer2"),
Dense(32,activation = "relu", name = "layer"),
Dense(10, activation = "softmax")
])
def compileModel(model):
model.compile(
optmizer = "adam",
loss = "sparse_categorical_crossentropy",
accuracy = ["accuracy"]
)
model = getModel(x_train_imgs.shape[0].shape)
compileModel(model)
model.fit(x_train_imgs, y_train_labs)
在这一点上,我得到了错误。我发现一些帖子表明损失函数有一些不正确的地方。但由于我没有使用过一种热编码,我认为sparse_categorical_crossentropy
它是正确的。
任何想法是什么导致了这个问题?
解决方案
推荐阅读
- javascript - 使用 Hooks 正确更新分数(使用 React 和 Hooks 制作的剪刀石头布游戏)
- linux - 如何将 TXT 转换为 CSV?
- javascript - 带有正则表达式的电话号码(加号和空格)
- css - SCSS 未定义变量:"$general-grey" 但该变量实际已定义且不同
- java - 将 java 与 Oracle 18c 连接时出现 JDBC 错误
- python - 如何使用 Python 将半结构化文本文件加载到结构化格式的数据框中?
- angular - Angular 8 中 Observable 中的类型转换问题
- c# - C# PowerShell - AddScript 作为多个语句
- python - H5py,将匹配的行从巨大的 hdf5 文件合并到较小的数据集
- javascript - 如何使用 Context API 在 React 中组合多个 reducer