InvalidArgumentError:收到的标签值为5,超出了[0,5]的有效范围。?

2024-06-16 13:47:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我用VGG16模型训练了我的火车组,我只加载了5个不同的类图像,为什么我会在下面得到这个错误?我只加载5个类,我应该设置5个类。为什么超出范围

# Flatten the output layer to 1 dimension
x = layers.Flatten()(base_model.output)

# Add a fully connected layer with 512 hidden units and ReLU activation
x = layers.Dense(512, activation='relu')(x)

# Add a dropout rate of 0.5
x = layers.Dropout(0.5)(x)

# Add a final sigmoid layer for classification
x = layers.Dense(5, activation='softmax')(x)

model = tf.keras.models.Model(base_model.input, x)
InvalidArgumentError:  Received a label value of 5 which is outside the valid range of [0, 5).  Label values: 4 3 5 3 3 4 3 4 2 1 1 5 2 5 5 1 1 1 3 1 1 2 1 1 3 5 4 1 5 3 5 1 1 2 2 2 5 2 2 5 2 5 4 5 5 2 3 4 4 3 4 2 5 5 4 3 4 3 2 1 1 2 5 4

Tags: ofthe模型addlayeroutputbasemodel