Some useful fiftyone tips
Visualize dataset using fifty one
import fiftyone
import fire
import pathlib
def hash_str (text : str ):
h = 0
for ch in text :
h = (h * 281 ^ ord (ch ) * 997 ) & 0xFFFFFFFF
return h
def visualize (dataset_path : str ):
"""Visualizes a coco dataset using fiftyone desktop application"""
input_dir = pathlib .Path (dataset_path ).resolve ()
dataset_name = str (hash_str (str (input_dir )))
if input_dir .exists () and input_dir .is_dir ():
images_path = input_dir .joinpath ("images" )
instances_path = input_dir .joinpath ("instances.json" )
if images_path .exists () and instances_path .exists ():
if dataset_name in fiftyone .list_datasets ():
fiftyone .delete_dataset (dataset_name )
dataset = fiftyone .Dataset .from_dir (
data_path = str (images_path ),
labels_path = str (instances_path ),
dataset_type = fiftyone .types .COCODetectionDataset ,
name = dataset_name ,
)
session = fiftyone .launch_app (dataset , desktop = True )
session .wait ()
else :
print (
"expected instances.json and images directory at path: {}" .format (
input_dir
)
)
else :
print ("{} not a valid directory" .format (input_dir ))
if __name__ == "__main__" :
fire .Fire (visualize )
import fiftyone .utils .splits as fous
fous .random_split (dataset , {"train" : 0.9 , "val" : 0.1 })
train_view = dataset .match_tags ("train" )
val_view = dataset .match_tags ("val" )
train_view .export ("d:/brackets/samples/train" , fiftyone .types .COCODetectionDataset )
val_view .export ("d:/brackets/samples/val" , fiftyone .types .COCODetectionDataset )