首次运行机器学习项目



我正在尝试使用 Keras 运行我的第一个机器学习项目。我无法摆脱此错误:

TypeError: If class_mode="categorical", y_col="Label" column values must be type string, list or tuple.

我的代码如下所示:

# Load train images in batches from directory and apply augmentations
train_data_generator = train_data_generator.flow_from_dataframe(
train_dataframe,
IMG_DIRECTORY,
x_col="Filename",
y_col="Label",
target_size=RAW_IMG_SIZE,
batch_size=BATCH_SIZE,
classes=CLASSES,
class_mode="categorical")
# Load validation images in batches from directory and apply rescaling
val_data_generator = val_data_generator.flow_from_dataframe(
val_dataframe,
IMG_DIRECTORY,
x_col="Filename",
y_col="Label",
target_size=RAW_IMG_SIZE,
batch_size=BATCH_SIZE,
classes=CLASSES,
class_mode="categorical")
# Load test images in batches from directory and apply rescaling
test_data_generator = test_data_generator.flow_from_dataframe(
test_dataframe,
IMG_DIRECTORY,
x_col="Filename",
y_col="Label",
target_size=IMG_SIZE,
batch_size=BATCH_SIZE,
shuffle=False,
classes=CLASSES,
class_mode="categorical")

这些是我使用y_col的唯一 3 个地方,我看不到导致该错误的问题是什么。

您可以使用以下命令更改列标签dtype

dataframe.Label = dataframe.Label.astype(str)

最新更新