我试图从开放图像中获取一组图像,用于训练对象检测分类器。我发现,从开放图像中获取图像的最简单方法可能是使用python程序FiftyOne。使用FiftyOne,我可以通过在命令中指定类来下载属于特定类的图像。
我现在的问题是,我如何排除某些类别?
我想训练一个识别车辆牌照的分类器。在训练过程中,我需要正面和负面的例子图像。
由于我想识别车牌,而不是车辆,所以我想找出带有车辆的负面例子。
我的想法是从“汽车”类中得到负面的例子,但它们不应该是“车辆登记牌”类的一部分。
有没有一种方法可以告诉create命令,它不应该包含带有“车辆登记牌”类的图像?
我目前使用的命令如下:
dataset = foz.load_zoo_dataset("open-images-v6", split="train", classes="Car", max_samples=10000)
然而,这下载的图像,也属于类别“车辆登记牌”,我不想要。
除了获取培训数据之外,我不想将FiftyOne用于其他任何事情。
即使它与这个问题没有任何关系:
我将使用OpenCV来训练和使用分类器。
发布于 2021-12-08 16:14:14
下载汽车图片后,您可以使用filtering capabilities of FiftyOne来区分任务中的正反两类。在从FiftyOne Zoo下载数据集时,无法明确排除类。
Open提供示例级的positive和negative标签,这些标签指示一个类是否确实存在于示例中。但是,这些都不是详尽的标记,因此,如果类不存在于任何一个样本级注释中,那么就无法知道它是否存在。
因此,有几种方法可以为您的任务获取所有相关的示例。
1)只使用带有附加注释的车辆牌号的样本
from fiftyone import ViewField as F
class_name = "Vehicle registration plate"
# Find samples that have a "Vehicle registration plate"
pos_view = dataset.filter_labels("positive_labels", F("label")==class_name)
# Find all samples that don't have a "Vehicle registration plate"
neg_view = dataset.filter_labels("negative_labels", F("label")==class_name)这是获取样本的最快方法,您可以确定是否有车牌。但是,在没有标注车牌的情况下,您将丢弃这些示例。
2)手动筛选出未标记的样本
如果您需要尽可能多的数据,那么您可以手动浏览没有标注车牌的示例,并找到更多的负面示例。
from fiftyone import ViewField as F
class_name = "Vehicle registration plate"
# Find samples that have a "Vehicle registration plate"
pos_view = dataset.filter_labels("positive_labels", F("label")==class_name)
# Find all samples without a positively labeled "Vehicle registration plate"
neg_view = dataset.exclude(pos_view)从这里开始,启动FiftyOne App并标记所有有盘子的样本。

# Tag any samples that have a plate in the App with "remove"
session = fo.launch_app(view=neg_view)
# Find and remove all tagged samples from the DatasetView
neg_view = neg_view.match_tags("remove", bool=False)然后,您可以将数据导出到variety of formats中的磁盘,以训练模型。如果您需要的格式没有列出,您可以简单地使用iterate over your dataset and save the data manually。
neg_view.export(
export_dir="/path/to/dir",
dataset_type=fo.types.COCODetectionDataset,
label_field="detections",
)一旦您对您的模型进行了培训,我建议您使用FiftyOne到visualize/analyze your predictions来了解您的模型是如何执行的,以便您能够改进它。
https://stackoverflow.com/questions/70274971
复制相似问题