python - flow_from_data_frame 在 keras 的多输出分类中给出了错误的标签形状
问题描述
我目前正在尝试在 keras 中训练一个多输出分类网络。.csv 有 4 个类别,它们都是来自 {0, 1, 2, 3, 4} 的类。我的网络有一个 softmax 密集层作为其输出层,但尝试训练给我以下错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must have the same first dimension, got logits shape [32,4] and labels shape [128]
[[node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at /engagement_detector/cnn/train.py:58) ]] [Op:__inference_train_function_1752]
由于我的批量大小在训练和生成器中都是 32,所以我原以为两者都是形状 [32, 4]。这是我用于生成器的代码:
datagen = datagen.flow_from_dataframe(
dataframe=df,
directory=subdir,
x_col="ClipID",
y_col=list(df.columns.drop("ClipID")),
subset=subset.lower(),
batch_size=32,
seed=42,
shuffle=True,
class_mode="raw",
target_size=(32, 32))
我做错了什么还是有人可以帮助我调整生成器输出的大小?我尝试添加一个重塑图层,但无法让它工作。
解决方案
推荐阅读
- javascript - 使用暂停和恢复功能自动化滑块
- c - 2个线程并行运行并等待相同的条件
- vb.net - 来自 DB 的 TileControl DevExpress
- parallax - translateZ 视差滚动不起作用
- libgdx - Libgdx freetypefont 不显示右边框颜色
- python-3.x - 从 .txt 文件中提取文本并保存到带有列和标题的 .csv 文件中
- r - 如何在 R 或 Python 中将县 FIPS 转换为经纬度坐标?
- c# - 在运行时更改 MVC 中的验证消息
- system-verilog - 为什么 uvm_tlm_fifo 需要 put_export 和 get_peek_export?
- macos - 在 MacOS 上将 OpenSSL 更新到 1.1.1