首页 > 解决方案 > 图像识别 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它是正确的。

任何想法是什么导致了这个问题?

标签: pythontensorflowkeras

解决方案


推荐阅读