Skip to content

gerd.models.label

Data definitions for Label Studio tasks.

The defined models and enums are used to parse and work with Label Studio data exported as JSON.

Classes:

Name Description
LabelStudioAnnotation

Annotation of a Label Studio task.

LabelStudioAnnotationResult

Result of a Label Studio annotation.

LabelStudioAnnotationValue

Value of a Label Studio annotation.

LabelStudioLabel

Labels for the GRASCCO Label Studio annotations.

LabelStudioTask

Task of a Label Studio project.

Functions:

Name Description
load_label_studio_tasks

Load Label Studio tasks from a JSON file.

LabelStudioAnnotation

Bases: BaseModel

Annotation of a Label Studio task.

A collection of annotations is associated with a task.

Attributes:

Name Type Description
completed_by int

The user ID of the user who completed the annotation.

created_at str

The creation date of the annotation.

draft_created_at Optional[str]

The creation date of the draft.

ground_truth bool

Whether the annotation is ground truth.

id int

The ID of the annotation.

import_id Optional[str]

The import ID of the annotation.

last_action Optional[str]

The last action of the annotation.

last_created_by Optional[int]

The user ID of the user who last created the annotation.

lead_time float

The lead time of the annotation.

parent_annotation Optional[str]

The parent annotation.

parent_prediction Optional[str]

The parent prediction.

prediction Dict[str, str]

The prediction of the annotation.

project int

The project ID of the annotation.

result List[LabelStudioAnnotationResult]

The results of the annotation.

result_count int

The number of results.

task int

The task ID of the annotation.

unique_id str

The unique ID of the annotation.

updated_at str

The update date of the annotation.

updated_by int

The user ID of the user who updated the annotation.

was_cancelled bool

Whether the annotation was cancelled.

completed_by instance-attribute

completed_by: int

The user ID of the user who completed the annotation.

created_at instance-attribute

created_at: str

The creation date of the annotation.

draft_created_at instance-attribute

draft_created_at: Optional[str]

The creation date of the draft.

ground_truth instance-attribute

ground_truth: bool

Whether the annotation is ground truth.

id instance-attribute

id: int

The ID of the annotation.

import_id instance-attribute

import_id: Optional[str]

The import ID of the annotation.

last_action instance-attribute

last_action: Optional[str]

The last action of the annotation.

last_created_by instance-attribute

last_created_by: Optional[int]

The user ID of the user who last created the annotation.

lead_time instance-attribute

lead_time: float

The lead time of the annotation.

parent_annotation instance-attribute

parent_annotation: Optional[str]

The parent annotation.

parent_prediction instance-attribute

parent_prediction: Optional[str]

The parent prediction.

prediction instance-attribute

prediction: Dict[str, str]

The prediction of the annotation.

project instance-attribute

project: int

The project ID of the annotation.

result instance-attribute

result: List[LabelStudioAnnotationResult]

The results of the annotation.

result_count instance-attribute

result_count: int

The number of results.

task instance-attribute

task: int

The task ID of the annotation.

unique_id instance-attribute

unique_id: str

The unique ID of the annotation.

updated_at instance-attribute

updated_at: str

The update date of the annotation.

updated_by instance-attribute

updated_by: int

The user ID of the user who updated the annotation.

was_cancelled instance-attribute

was_cancelled: bool

Whether the annotation was cancelled.

LabelStudioAnnotationResult

Bases: BaseModel

Result of a Label Studio annotation.

Attributes:

Name Type Description
from_name str

The name of the source.

id str

The ID of the result.

origin str

The origin of the result.

to_name str

The name of the target.

type str

The type of the result.

value LabelStudioAnnotationValue

The value of the result.

from_name instance-attribute

from_name: str

The name of the source.

id instance-attribute

id: str

The ID of the result.

origin instance-attribute

origin: str

The origin of the result.

to_name instance-attribute

to_name: str

The name of the target.

type instance-attribute

type: str

The type of the result.

value instance-attribute

value: LabelStudioAnnotationValue

The value of the result.

LabelStudioAnnotationValue

Bases: BaseModel

Value of a Label Studio annotation.

Attributes:

Name Type Description
end int

The end of the annotation.

labels List[LabelStudioLabel]

The labels of the annotation.

start int

The start of the annotation.

end instance-attribute

end: int

The end of the annotation.

labels instance-attribute

labels: List[LabelStudioLabel]

The labels of the annotation.

start instance-attribute

start: int

The start of the annotation.

LabelStudioLabel

Bases: Enum

Labels for the GRASCCO Label Studio annotations.

LabelStudioTask

Bases: BaseModel

Task of a Label Studio project.

A task is a single unit of work that can be annotated by a user. Tasks can be used to train an auto labeler or to evaluate the performance of a model.

Attributes:

Name Type Description
annotations List[LabelStudioAnnotation]

The annotations of the task.

cancelled_annotations int

The number of cancelled annotations.

comment_authors List[str]

The authors of the comments.

comment_count int

The number of comments.

created_at str

The creation date of the task.

data Optional[Dict[str, str]]

The data of the task.

drafts List[str]

The drafts of the task.

file_name str

Extracts the original file name from the file upload.

file_upload str

The file upload of the task.

id int

The ID of the task.

inner_id int

The inner ID of the task.

last_comment_updated_at Optional[str]

The update date of the last comment.

meta Optional[Dict[str, str]]

The meta data of the task.

predictions List[str]

The predictions of the task.

project int

The project ID of the task.

total_annotations int

The total number of annotations.

total_predictions int

The total number of predictions.

unresolved_comment_count int

The number of unresolved comments.

updated_at str

The update date of the task.

updated_by int

The user ID of the user who updated the task.

annotations instance-attribute

annotations: List[LabelStudioAnnotation]

The annotations of the task.

cancelled_annotations instance-attribute

cancelled_annotations: int

The number of cancelled annotations.

comment_authors instance-attribute

comment_authors: List[str]

The authors of the comments.

comment_count instance-attribute

comment_count: int

The number of comments.

created_at instance-attribute

created_at: str

The creation date of the task.

data instance-attribute

data: Optional[Dict[str, str]]

The data of the task.

drafts instance-attribute

drafts: List[str]

The drafts of the task.

file_name property

file_name: str

Extracts the original file name from the file upload.

File uploads are stored as project-id-filename format to be unique.

file_upload instance-attribute

file_upload: str

The file upload of the task.

id instance-attribute

id: int

The ID of the task.

inner_id instance-attribute

inner_id: int

The inner ID of the task.

last_comment_updated_at instance-attribute

last_comment_updated_at: Optional[str]

The update date of the last comment.

meta instance-attribute

meta: Optional[Dict[str, str]]

The meta data of the task.

predictions instance-attribute

predictions: List[str]

The predictions of the task.

project instance-attribute

project: int

The project ID of the task.

total_annotations instance-attribute

total_annotations: int

The total number of annotations.

total_predictions instance-attribute

total_predictions: int

The total number of predictions.

unresolved_comment_count instance-attribute

unresolved_comment_count: int

The number of unresolved comments.

updated_at instance-attribute

updated_at: str

The update date of the task.

updated_by instance-attribute

updated_by: int

The user ID of the user who updated the task.

load_label_studio_tasks

load_label_studio_tasks(file_path: str) -> List[LabelStudioTask]

Load Label Studio tasks from a JSON file.

Parameters:

Name Type Description Default

file_path

str

The path to the JSON file.

required

Returns:

Type Description
List[LabelStudioTask]

The loaded Label Studio tasks

Source code in gerd/models/label.py
def load_label_studio_tasks(file_path: str) -> List[LabelStudioTask]:
    """Load Label Studio tasks from a JSON file.

    Parameters:
        file_path: The path to the JSON file.

    Returns:
        The loaded Label Studio tasks
    """
    with open(file_path, "r", encoding="utf-8") as f:
        obj = json.load(f)

    tasks = TypeAdapter(List[LabelStudioTask]).validate_python(obj)
    return tasks