create_label_set
imerit_ango.sdk.SDK.
create_label_set(project_id, tools, classifications, relations, raw_category_schema)
Create and set the project's ontology.
Parameters
project_id: string
The unique identifier for the project. You can find the project ID in the user interface or retrieve it using the
list_projects
function.
tools: List[ToolCategory], optional
List of tools that will be added to the label set.
Example:
[ToolCategory(Tool.Segmentation, title="SegmentationTool")]
classifications: List[ClassificationCategory], optional, default None
List of classifications that will be added to the label set.
Example:
[ClassificationCategory(Classification.Single_dropdown, title = "Choice", options=[LabelOption("First"), LabelOption("Second")])]
relations: List[RelationCategory], optional, default None
List of relations that will be added to the label set.
Example:
[RelationCategory(Relation.Single, title="SingleRelationTool")]
raw_category_schema: Dict, optional, default None
Instead of creating the label set (category schema) using the previous 'tools', 'classifications', and 'relations' parameters, you may pass here a dictionary representing the entire category schema.
See the section below for an example.
To get an example of what can be passed as the raw_category_schema
, there are two ways:
Using the SDK itself, get the category schema from another existing project. This will also allow you to programmatically copy the category schema between two projects, like so:
From the UI, navigate to an existing project, then from the Settings tab, navigate to the Category Schema section. From there, click on the
button on the right side to open the schema's JSON. Copy that JSON.
As an example, a raw_category_schema
obtained from a project could be this:
Label Set Classes
ToolCategory
BoundingBox
Segmentation
Polyline
Polygon
RotatedBoundingBox
Ner
Point
Pdf
Brush
ToolCategory Parameters:
tool: Tool
The tool type. ex.:
Tool.Segmentation
title: string, default ""
The title of the tool.
required: bool, default None
Whether annotators are required to draw at least one instance of this tool.
schemaId: string, default None
Sets the tool's schemaId.
columnField: bool, default False
Whether this tool should be a table column.
color: string, default ""
The color assigned to this labeling tool, in the format "#FFFFFF"
shortcutKey: string, default ""
The shortcut to quickly select this tool, "0"-"9", "ctrl+0"-"ctrl+9", "a"-"k"
classifications: List[ClassificationCategory], default []
List of nested classifications, if any
options: List[LabelOption], default []
The tool's answers (options)
LabelOption parameters:
value: string
The text of the answer (option).
schemaId: string, default None
The schema ID of the option. Necessary for conditional nesting.
Returns:
output: dict
Examples
Example-1: Creating an ontology with:
A Single Dropdown classification, with two choices named "First" and "Second":
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.label_category import LabelOption, ClassificationCategory, Classification
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')
ango_sdk = SDK(api_key)
category = ClassificationCategory(Classification.Single_dropdown,
title = "Choice",
options = [LabelOption("First"),
LabelOption("Second")])
label_set = [category]
response = ango_sdk.create_label_set(project_id=project_id, classifications=label_set)
Example-2: Creating an ontology with:
A Single Dropdown classification with the classifications "First" and "Second"
A Segmentation tool called "SegmentationTool"
A Single Relation called "SingleRelationTool"
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.label_category import ClassificationCategory, Classification, LabelOption, Tool, ToolCategory, RelationCategory, Relation
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')
ango_sdk = SDK(api_key)
dropdown = ClassificationCategory(Classification.Single_dropdown,
title = "SingleDropdown",
options = [LabelOption('First'),
LabelOption('Second')])
classifications = [dropdown]
segmentation = ToolCategory(Tool.Segmentation, title="SegmentationTool")
tools = [segmentation]
relation = RelationCategory(Relation.Single, title="SingleRelationTool")
relations = [relation]
ango_sdk.create_label_set(project_id=project_id,
tools=tools,
classifications=classifications,
relations=relations)
Example-3: Creating an ontology with:
A Single Dropdown classification called "Entity Type" with the choices "Vehicle" and "Person"
Another Single Dropdown classification nested inside the first unconditionally (that is, any choice in the first dropdown will open this second) named "Position" with the choices "On Road" and "Off Road".
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.label_category import ClassificationCategory, LabelOption, Classification
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')
ango_sdk = SDK(api_key)
nested_class_in_dropdown = ClassificationCategory(Classification.Single_dropdown,
title="Position",
options=[LabelOption('On Road'),
LabelOption('Off Road')])
dropdown = ClassificationCategory(Classification.Single_dropdown,
title="Entity Type",
options=[LabelOption('Vehicle'),
LabelOption('Person')],
classifications=[nested_class_in_dropdown],
required=True)
classifications = [dropdown]
ango_sdk.create_label_set(project_id=project_id, classifications=classifications)
Example-4: Creating an ontology with:
A Tree Dropdown tool with:
A root
With a "tree0" branch
With a "subtree0" leaf
With a "subtree1" leaf
With a "tree1" leaf
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.label_category import ClassificationCategory, Classification, TreeOption
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')
ango_sdk = SDK(api_key)
subtree0 = TreeOption(title="subtree0")
subtree1 = TreeOption(title="subtree1")
tree0 = TreeOption(title="tree0", children=[subtree0, subtree1])
tree1 = TreeOption(title="tree1")
tree_tool = ClassificationCategory(classification=Classification.Tree_dropdown,
title="Tree One",
treeOptions=[tree0, tree1])
ango_sdk.create_label_set(project_id=project_id, classifications=[tree_tool])
Example-5: Creating an ontology with:
A radio classification tool with two possible answers, "Radio Option 1" and "Radio Option 2"
A conditionally nested Text classification tool using the rich text editor, which only appears if the labeler clicks on "Radio Option 1" (here,
parentOptionId
links the text tool to the option which reveals it)
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.label_category import ClassificationCategory, LabelOption, Classification
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')
ango_sdk = SDK(api_key)
radio1 = LabelOption(value="Radio Option 1", schemaId="radioOption1SchemaId")
radio2 = LabelOption(value="Radio Option 2")
conditional_text = ClassificationCategory(classification=Classification.Text,
title="Text Tool",
parentOptionId="radioOption1SchemaId",
color="#333333",
richText=True)
radio = ClassificationCategory(classification=Classification.Radio,
title="Radio Classification",
options=[radio1, radio2],
classifications=[conditional_text])
ango_sdk.create_label_set(project_id=project_id, classifications=[radio])
Example-6: Creating an ontology with:
A radio classification tool with the possible answers "Radio Answer 1" and "Radio Answer 2"
A Tree Dropdown classification tool which only appears if the annotator clicks on "Radio Answer 1"
The Tree Dropdown has a main root
With a branch called "Branch 1"
With leaves called "Leaf 1" and "Leaf 2"
With a leaf called "Leaf 3"
import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.label_category import ClassificationCategory, TreeOption, LabelOption, Classification
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')
ango_sdk = SDK(api_key)
leaf1 = TreeOption(title="Leaf 1")
leaf2 = TreeOption(title="Leaf 2")
leaf3 = TreeOption(title="Leaf 3")
branch1 = TreeOption(title="Branch 1",
children=[leaf1, leaf2])
tree_tool = ClassificationCategory(classification=Classification.Tree_dropdown,
title='tree',
treeOptions=[branch1, leaf3],
parentOptionId="radioOptionSchemaId")
radio1 = LabelOption(value="Radio Answer 1")
radio2 = LabelOption(value="Radio Answer 2")
radio = ClassificationCategory(classification=Classification.Radio,
title='radio',
classifications=[tree_tool],
options=[radio1, radio2])
ango_sdk.create_label_set(project_id=project_id, classifications=[radio])
Last updated