FiftyOne——进阶使用方法
数据集
按索引从数据集中取出样本
#
index = 10
dataset.skip(index-1).limit(1).first() # 大概的意思是跳过index-1个样本 取出1个样本(此时是一个dataset_view),需要调用first(),取出第一个样本,也就是目标样本
detection中添加自定义的属性
最好是内建的数据类型:
- 初始化时候添加
sample["ground_truth"] = fo.Detections(
detections=[
fo.Detection(
label="cat",
bounding_box=[0.5, 0.5, 0.4, 0.3],
attributes={
"age": fo.NumericAttribute(value=51),
"mood": fo.CategoricalAttribute(value="salty"),
},
),
]
)
- 直接添加
detection.age = fo.NumericAttribute(value = 1)# 原本样本中并没有age这个属性
detection.age = 1 # 也可以,但不建议
- 放在attributes里面
sample["ground_truth"] = fo.Detections(
detections=[
fo.Detection(
label="cat",
bounding_box=[0.5, 0.5, 0.4, 0.3],
attributes={
"age": fo.NumericAttribute(value=51),
"mood": fo.CategoricalAttribute(value="salty"),
},
),
]
)
合并两个数据集
- 完全合同
dataset1 = ...# 数据集1
dataset2 = ...# 数据集2
# 将数据集2添加到数据集1中
dataset1.add_samples(dataset2)
- 将数据集1中有标注的部分合并到数据集2
dataset1 = ...
dataset1_有标注 = dataset1.exists("ground_truth")
dataset2.add_samples(dataset1_有标注)
标签Tags
- 获得所有标签名
tags = list(dataset.count_sample_tags().keys())