Recipes and Ontologies: Your Data's Secret Sauce π§ͺ
Welcome to the world of recipes and ontologies in Dataloop! Think of recipes as your master cookbook π and ontologies as your ingredient lists π. Let's dive in and learn how to create the perfect data labeling recipe!
Understanding the Basics π
What's a Recipe? π³
A recipe in Dataloop is like your cooking instructions - it tells annotators exactly how to label your data. It includes:
- π Link to an ontology (your ingredients)
- π οΈ Labeling tools (box, polygon, etc.)
- π Optional PDF instructions
- β¨ And more goodies!
What's an Ontology? π³
An ontology is your structured knowledge base that contains:
- π·οΈ Labels (like "Dog", "Cat", "Car")
- π Attributes (properties like "Color", "Size")
- π Relationships between labels and attributes
Working with Recipes π§βπ³
Basic Recipe Operations
import dtlpy as dl
if dl.token_expired():
dl.login()
# Get your project and dataset
project = dl.projects.get(project_name='project_name')
dataset = project.datasets.get(dataset_name='dataset_name')
# Get a recipe from the list
recipe = dataset.recipes.list()[0]
# Get a specific recipe by ID
recipe = dataset.recipes.get(recipe_id='your-recipe-id')
# Delete a recipe (only works on deleted datasets)
dataset.recipes.get(recipe_id='your-recipe-id').delete()
Cloning Recipes π
Need a recipe that's similar to an existing one? Clone it! It's like copying your grandma's recipe and adding your own twist.
# Clone with options:
# shallow=True: Links to existing ontology
# shallow=False: Creates new copies of all linked ontologies
recipe2 = recipe.clone(shallow=False)
Switching Dataset Recipes π
Want to try a different recipe on your dataset? Here's how:
dataset = project.datasets.get(dataset_name="myDataSet")
recipe = dataset.switch_recipe(recipe_id="recipe_id")
Creating Your Ontology π
Starting Fresh
# Create a new ontology with a starter label
ontology = project.ontologies.create(
title="my_awesome_ontology",
labels=[dl.Label(tag="Chameleon", color=(255, 0, 0))]
)
Adding Labels π·οΈ
You've got multiple ways to add labels - pick your favorite!
Method 1: Quick Add
# Add multiple labels at once
dataset.add_labels(label_list=['person', 'animal', 'object'])
# Add a single label with style
dataset.add_label(
label_name='person',
color=(34, 6, 231),
icon_path='/home/project/images/icon.jpg'
)
Method 2: Using Label Objects
# Create fancy labels with colors
labels = [
dl.Label(tag='Donkey', color=(255, 100, 0)),
dl.Label(tag='Mammoth', color=(34, 56, 7)),
dl.Label(tag='Bird', color=(100, 14, 150))
]
dataset.add_labels(label_list=labels)
Creating Label Hierarchies π²
Want to organize your labels like a family tree? Here's how:
# Create a parent label with children
label = dl.Label(
tag='Fish',
color=(34, 6, 231),
children=[
dl.Label(tag='Shark', color=(34, 6, 231)),
dl.Label(tag='Salmon', color=(34, 6, 231))
]
)
dataset.add_labels(label_list=label)
The Big Nested Labels Adventure πΊοΈ
Want to create complex hierarchies? Try this super-powered approach:
nested_labels = [
{
'label_name': 'animal.Dog',
'color': '#220605',
'children': [
{'label_name': 'poodle', 'color': '#298345'},
{'label_name': 'labrador', 'color': '#298651'}
]
},
{
'label_name': 'animal.cat',
'color': '#287605',
'children': [
{'label_name': 'Persian', 'color': '#298345'},
{'label_name': 'Balinese', 'color': '#298651'}
]
}
]
labels = dataset.add_labels(label_list=nested_labels)
Working with Attributes π¨
Attributes are like special powers for your labels. They help describe additional properties without creating new labels.
Types of Attributes
- β Checkbox (Multiple Choice)
ontology.update_attributes(
key='color',
title='Choose a color',
attribute_type=dl.AttributesTypes.CHECKBOX,
values=['red', 'blue', 'green'],
scope=['<label1>', '<label2>']
)
- π Radio Button (Single Choice)
ontology.update_attributes(
key='occluded',
title='Level of occlusion',
attribute_type=dl.AttributesTypes.RADIO_BUTTON,
values=['no', 'mid', 'high'],
scope=['*']
)
- ποΈ Slider
ontology.update_attributes(
key='height',
title='Person height[cm]',
attribute_type=dl.AttributesTypes.SLIDER,
attribute_range=dl.AttributesRange(0, 200, 10),
scope=['*']
)
- β Yes/No Question
ontology.update_attributes(
key='female',
title='Is mosquito female?',
attribute_type=dl.AttributesTypes.YES_NO,
scope=['*']
)
- βοΈ Free Text
ontology.update_attributes(
key='age',
title='How old is the person',
attribute_type=dl.AttributesTypes.FREE_TEXT,
scope=['*']
)
Handy Tips and Tricks π‘
- View All Labels
# Get all labels (including children)
print(ontology.labels_flat_dict)
- Check Attributes
# See all attributes
print(ontology.metadata['attributes'])
# Get attribute keys
keys = [att['key'] for att in ontology.metadata['attributes']]
- Update Labels
# Update existing label
dataset.update_label(label_name='Cat', color="#000080")
# Update or create if not exists
dataset.update_label(label_name='Cat', color="#fcba03", upsert=True)
- Delete Labels
dataset.delete_labels(label_names=['Cat', 'Dog'])
Best Practices π
- π Plan your ontology structure before creating it
- π¨ Use consistent color schemes for related labels
- π Keep your attribute choices clear and concise
- π³ Don't go too deep with label hierarchies (max 5 levels)
- π Test your recipe with a small dataset first
Need More Help? π€
- Check out our Recipe Documentation
- Visit our Ontology Guide
Happy labeling! π