如何在Keras多标签图像分类中包含背景图像?
我一直在尝试培训一个多标签分类模型,并希望包括没有标签来改进培训的图像。我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论