如何在Keras多标签图像分类中包含背景图像?

发布于 2025-01-24 23:12:14 字数 1033 浏览 4 评论 0原文

我一直在尝试培训一个多标签分类模型,并希望包括没有标签来改进培训的图像。我正在使用flow_from_dataframe加载数据,并将空的标签列表视为新类。我还尝试将类列表传递到此功能中,在这种情况下,它完全忽略了没有标签的图像。如何在Keras没有标签的图像上训练?

我想使用的数据框的示例:

0                        2022-04-06-16-15-18-209181.jpg            []
1                        2022-04-11-19-14-50-087726.jpg            []
2                        2022-04-06-16-15-11-507593.jpg            []
3                        2022-04-05-18-53-55-625837.jpg            [class1]
...                                                 ...                ...
3631                     2022-04-06-14-09-19-008147.jpg  [class1, class2]
3632                     2022-04-05-18-14-48-329041.jpg  [class1, class2]

代码:

train_generator = datagen.flow_from_dataframe(
    df,
    directory=data_dir + "/images",
    x_col='filename',
    y_col='labels',
    class_mode='categorical',
    shuffle=True,
    target_size=(IMAGE_SIZE, IMAGE_SIZE),
    batch_size=BATCH_SIZE, 
    subset='training',
    seed=42)

I have been trying to train a multilabel classification model and want to include images that have no label to improve the training. I am using flow_from_dataframe to load the data and it sees the empty label list as a new class. I have also tried passing the class list into this function, in this case it completely ignores the images with no label. How can I train on images with no label in Keras?

Example of the dataframe I want to use:

0                        2022-04-06-16-15-18-209181.jpg            []
1                        2022-04-11-19-14-50-087726.jpg            []
2                        2022-04-06-16-15-11-507593.jpg            []
3                        2022-04-05-18-53-55-625837.jpg            [class1]
...                                                 ...                ...
3631                     2022-04-06-14-09-19-008147.jpg  [class1, class2]
3632                     2022-04-05-18-14-48-329041.jpg  [class1, class2]

Code:

train_generator = datagen.flow_from_dataframe(
    df,
    directory=data_dir + "/images",
    x_col='filename',
    y_col='labels',
    class_mode='categorical',
    shuffle=True,
    target_size=(IMAGE_SIZE, IMAGE_SIZE),
    batch_size=BATCH_SIZE, 
    subset='training',
    seed=42)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文