import fiftyone.zoo as foz
oi_dataset = foz.load_zoo_dataset("open-images-v6", split="validation")classes, split, max_samples, and more:import fiftyone as fo
import fiftyone.zoo as foz
dataset = foz.load_zoo_dataset(
"open-images-v6",
"validation",
label_types=["detections", "classifications"],
classes = ["Dog", "Cat"],
max_samples=1000,
seed=51,
shuffle=True,
dataset_name="open-images-dog-cat",
)
session = fo.launch_app(dataset)results = fo.evaluate_detections(
dataset,
pred_field="predictions",
gt_field="detections",
pos_label_field="positive_labels",
neg_label_field="negative_labels",
hierarchy = dataset.info["hierarchy"],
method = "open-images",
expand_pred_hierarchy=True,
)pip install awscli
aws s3 --no-sign-request sync s3://open-images-dataset/test ./open-images/test/ball . If there isn’t one, that would be a good negative label.wget -P labels https://storage.googleapis.com/openimages/v5/test-annotations-human-imagelabels-boxable.csvwget -P labels https://storage.googleapis.com/openimages/v5/class-descriptions-boxable.csvwget -P detections https://storage.googleapis.com/openimages/v5/test-annotations-bbox.csvis, indicating if an object is some attribute (like if a handbag is leather). The annotations for these relationships include the bounding boxes and labels of both objects as well as the label for the relationship.wget -P relationships https://storage.googleapis.com/openimages/v6/oidv6-test-annotations-vrd.csv
wget -P relationships https://storage.googleapis.com/openimages/v6/oidv6-attributes-description.csv0–9 or A-F. In this example, we will only be using images starting with 0. The following command downloads just those masks, replace the 0 with 1-9 or a-f to download masks for other images.wget -P segmentations https://storage.googleapis.com/openimages/v5/test-masks/test-masks-0.zip
unzip -d segmentations/masks segmentations/test-masks-0.zip
wget -P segmentations https://storage.googleapis.com/openimages/v5/test-annotations-object-segmentation.csvcsv files we downloaded and parse them to find a subset of images we want to use.import csv
with open("detections/test-annotations-bbox.csv") as f:
reader = csv.reader(f, delimiter=',')
det_data = [row for row in reader]
with open("labels/test-annotations-human-imagelabels-boxable.csv") as f:
reader = csv.reader(f, delimiter=',')
lab_data = [row for row in reader]
with open("relationships/oidv6-test-annotations-vrd.csv") as f:
reader = csv.reader(f, delimiter=',')
rel_data = [row for row in reader]
with open("segmentations/test-annotations-object-segmentation.csv") as f:
reader = csv.reader(f, delimiter=',')
seg_data = [row for row in reader]
# Find intersection of ImageIDs with all annotations
det_ids = {l[0] for l in det_data[1:]}
lab_ids = {l[0] for l in lab_data[1:]}
rel_ids = {l[0] for l in rel_data[1:]}
# We only downloaded the zip for files starting with "0"
seg_ids = {l[1] for l in seg_data[1:] if l[1][0] == "0"}
valid_ids = det_ids & lab_ids & rel_ids & seg_idsvalid_ids that contains all of the annotations we want to look at. Let's choose a subset of 100 of those and download the corresponding images following what is done in the official Open Images download script.pip install boto3import boto3
import botocore
import os
BUCKET_NAME = 'open-images-dataset'
bucket = boto3.resource(
's3', config=botocore.config.Config(
signature_version=botocore.UNSIGNED)).Bucket(BUCKET_NAME)
num_ids = 100
os.makedirs('images/test', exist_ok=True)
for image_id in list(valid_ids)[:num_ids]:
bucket.download_file(f'test/{image_id}.jpg',
os.path.join('images/test/', f'{image_id}.jpg'))import csv
with open("labels/class-descriptions-boxable.csv") as f:
reader = csv.reader(f, delimiter=',')
cls_data = [row for row in reader]
# Map of class IDs to class names
classes_map = {k: v for k,v in cls_data}
with open("relationships/oidv6-attributes-description.csv") as f:
reader = csv.reader(f, delimiter=',')
attrs_data = [row for row in reader]
# Map of attribute IDs to attribute names
attrs_map = {k: v for k,v in attrs_data}pip install fiftyone
pip install ipythonipython the first step is to create a FiftyOne Dataset.import fiftyone as fo
dataset = fo.Dataset("open_images_v6")persistent attribute to True. This lets us quickly load the dataset in the future.dataset.persistent = Truefield to our samples.fo.Classifications class. Detections, segmentations, and relations can all use the fo.Detections class since it supports bounding boxes, masks, and also custom attributes assigned to each detection. These custom attributes can be used for things like IsOccluded in the detections or the two labels that a relationship is between.fo.Classification class. Since these are multi-label classifications, we will be using the fo.Classifications class to store multiple classification labels.def create_labels(lab_data, image_id):
pos_cls = []
neg_cls = []
# Get relevant data for this image
sample_labs = [i for i in lab_data if i[0]==image_id]
for sample_lab in sample_labs:
# sample_lab reference: [ImageID,Source,LabelName,Confidence]
label = classes_map[sample_lab[2]]
conf = float(sample_lab[3])
cls = fo.Classification(label=label, confidence=conf)
if conf > 0.1:
pos_cls.append(cls)
else:
neg_cls.append(cls)
pos_labels = fo.Classifications(classifications=pos_cls)
neg_labels = fo.Classifications(classifications=neg_cls)
return pos_labels, neg_labelsfo.Detections class lets you store multiple fo.Detection objects in a list. We create a detection by defining the bounding box coordinates and class label of the object. We can then add any additional attributes that we want, like IsOccluded and IsTruncated.def create_detections(det_data, image_id):
dets = []
sample_dets = [i for i in det_data if i[0]==image_id]
for sample_det in sample_dets:
# sample_det reference: [ImageID,Source,LabelName,Confidence,XMin,XMax,YMin,YMax,IsOccluded,IsTruncated,IsGroupOf,IsDepiction,IsInside]
label = classes_map[sample_det[2]]
xmin = float(sample_det[4])
xmax = float(sample_det[5])
ymin = float(sample_det[6])
ymax = float(sample_det[7])
# Convert to [top-left-x, top-left-y, width, height]
bbox = [xmin, ymin, xmax-xmin, ymax-ymin]
detection = fo.Detection(bounding_box=bbox, label=label)
detection["IsOccluded"] = bool(int(sample_det[8]))
detection["IsTruncated"] = bool(int(sample_det[9]))
detection["IsGroupOf"] = bool(int(sample_det[10]))
detection["IsDepiction"] = bool(int(sample_det[11]))
detection["IsInside"] = bool(int(sample_det[12]))
dets.append(detection)
detections = fo.Detections(detections=dets)
return detectionsfo.Detections since a relationship contains a bounding box, relationship label, and object labels, all of which can be stored in a detection. We are going to have the bounding box of the relationship encompass the bounding boxes of both objects it pertains to. We add the labels of each object as additional custom fields to the detection.def create_relationships(rel_data, image_id):
rels = []
sample_rels = [i for i in rel_data if i[0]==image_id]
for sample_rel in sample_rels:
# sample_rel reference: [ImageID,LabelName1,LabelName2,XMin1,XMax1,YMin1,YMax1,XMin2,XMax2,YMin2,YMax2,RelationshipLabel]
label1 = classes_map[sample_rel[1]]
attribute = False
if sample_rel[2] in classes_map:
label2 = classes_map[sample_rel[2]]
else:
label2 = attrs_map[sample_rel[2]]
attribute = True
label_rel = sample_rel[-1]
xmin1 = float(sample_rel[3])
xmax1 = float(sample_rel[4])
ymin1 = float(sample_rel[5])
ymax1 = float(sample_rel[6])
xmin2 = float(sample_rel[7])
xmax2 = float(sample_rel[8])
ymin2 = float(sample_rel[9])
ymax2 = float(sample_rel[10])
xmin_int = min(xmin1, xmin2)
ymin_int = min(ymin1, ymin2)
xmax_int = max(xmax1, xmax2)
ymax_int = max(ymax1, ymax2)
# Convert to [top-left-x, top-left-y, width, height]
bbox_int = [xmin_int, ymin_int, xmax_int-xmin_int, ymax_int-ymin_int]
detection_rel = fo.Detection(bounding_box=bbox_int, label=label_rel)
detection_rel["Label1"] = label1
detection_rel["Label2"] = label2
rels.append(detection_rel)
relationships = fo.Detections(detections=rels)
return relationships fo.Detections to store segmentations since a detection contains an optional mask argument that accepts a NumPy array and will scale it to the bounding box region. The segmentations in Open Images also contain a bounding box around the mask as well as the instance label, all of which is added to the detection objects.def create_segmentations(seg_data, image_id):
segs = []
sample_segs = [i for i in seg_data if i[1]==image_id]
for sample_seg in sample_segs:
# sample_seg reference: [MaskPath,ImageID,LabelName,BoxID,BoxXMin,BoxXMax,BoxYMin,BoxYMax,PredictedIoU,Clicks]
label = classes_map[sample_seg[2]]
xmin = float(sample_seg[4])
xmax = float(sample_seg[5])
ymin = float(sample_seg[6])
ymax = float(sample_seg[7])
# Convert to [top-left-x, top-left-y, width, height]
bbox = [xmin, ymin, xmax-xmin, ymax-ymin]
# Load boolean mask
mask_path = os.path.join("segmentations/masks", sample_seg[0])
mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE) > 122
h,w = mask.shape
cropped_mask = mask[int(ymin*h):int(ymax*h), int(xmin*w):int(xmax*w)]
segmentation = fo.Detection(bounding_box=bbox, label=label,
mask=cropped_mask)
segs.append(segmentation)
segmentations = fo.Detections(detections=segs)
return segmentationsfilepath to be instantiated and we can add any FiftyOne labels to a sample. Once the sample is created, we can add it to the dataset and continue until all of our data is loaded.# Add Samples to Dataset
for image_id in list(valid_ids)[:num_ids]:
sample = fo.Sample(filepath=os.path.join("images/test/%s.jpg" % image_id))
# Add Labels
pos_labels, neg_labels = create_labels(lab_data, image_id)
sample["positive_labels"] = pos_labels
sample["negative_labels"] = neg_labels
# Add Detections
detections = create_detections(det_data, image_id)
sample["detections"] = detections
# Add Segmentations
segmentations = create_segmentations(seg_data, image_id)
sample["segmentations"] = segmentations
# Add Relationships
relationships = create_relationships(rel_data, image_id)
sample["relationships"] = relationships
dataset.add_sample(sample)session = fo.launch_app(dataset)Ride relationships between Man and Horse in the image below.Mammal label has an inconsistent meaning between different samples. Below are two images containing humans, one has Mammal as a negative_label and the other has Mammal as a positive_label.Human face with a bounding box area greater than 0.2.from fiftyone import ViewField as F
bbox_area = F("bounding_box")[2] * F("bounding_box")[3]
large_face_view = (
dataset
.filter_labels(
"detections", F("label")=="Human face", only_matches=True
).filter_labels(
"detections", bbox_area > 0.2, only_matches=True
)
)
session.view = large_face_viewdetections that we added to MS-COCO format so that we can use the pycocotools evaluation on it, we can do so in one line of code in Python.dataset.export(
export_dir="/path/to/dir",
dataset_type=fo.types.COCODetectionDataset,
label_field="detections",
)import fiftyone as fo
dataset = fo.Dataset.from_dir("path/to/data", dataset_type=fo.types.CVATImageDataset)import fiftyone as fo
# Initialize your dataset
dataset = fo.Dataset(name)
# Get a list of image paths
images = ....
# Parse your labels into samples
for path in images:
sample = fo.Sample(path)
sample["label"] = fo.Classification(label=...)
detections = []
for det in parsed_detection_labels:
detection = fo.Detection(label=..., bounding_box=[...])
detections.append(detection)
sample["detections"] = fo.Detections(detections=detections)
dataset.add_sample(sample)
# Visualize your dataset in the FiftyOne App
session = fo.launch_app(dataset)© 2026 Voxel51 All Rights Reserved


