Last updated

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

  1. βœ… Checkbox (Multiple Choice)
ontology.update_attributes(
    key='color',
    title='Choose a color',
    attribute_type=dl.AttributesTypes.CHECKBOX,
    values=['red', 'blue', 'green'],
    scope=['<label1>', '<label2>']
)
  1. πŸ”˜ Radio Button (Single Choice)
ontology.update_attributes(
    key='occluded',
    title='Level of occlusion',
    attribute_type=dl.AttributesTypes.RADIO_BUTTON,
    values=['no', 'mid', 'high'],
    scope=['*']
)
  1. 🎚️ Slider
ontology.update_attributes(
    key='height',
    title='Person height[cm]',
    attribute_type=dl.AttributesTypes.SLIDER,
    attribute_range=dl.AttributesRange(0, 200, 10),
    scope=['*']
)
  1. ❓ Yes/No Question
ontology.update_attributes(
    key='female',
    title='Is mosquito female?',
    attribute_type=dl.AttributesTypes.YES_NO,
    scope=['*']
)
  1. ✍️ Free Text
ontology.update_attributes(
    key='age',
    title='How old is the person',
    attribute_type=dl.AttributesTypes.FREE_TEXT,
    scope=['*']
)

Handy Tips and Tricks πŸ’‘

  1. View All Labels
# Get all labels (including children)
print(ontology.labels_flat_dict)
  1. Check Attributes
# See all attributes
print(ontology.metadata['attributes'])
# Get attribute keys
keys = [att['key'] for att in ontology.metadata['attributes']]
  1. 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)
  1. Delete Labels
dataset.delete_labels(label_names=['Cat', 'Dog'])

Best Practices 🌟

  1. πŸ“ Plan your ontology structure before creating it
  2. 🎨 Use consistent color schemes for related labels
  3. πŸ“Š Keep your attribute choices clear and concise
  4. 🌳 Don't go too deep with label hierarchies (max 5 levels)
  5. πŸ”„ Test your recipe with a small dataset first

Need More Help? πŸ€”

Happy labeling! πŸš€