Utilities¶
converter¶
- class Converter(concurrency=6, return_error_filepath=False)[source]¶
Bases:
object
Annotation Converter
- attach_agent_progress(progress: Progress, progress_update_frequency: Optional[int] = None)[source]¶
Attach agent progress.
- Parameters:
progress (Progress) – the progress object that follows the work
progress_update_frequency (int) – progress update frequency in percentages
- convert(annotations, from_format: str, to_format: str, conversion_func=None, item=None)[source]¶
Convert annotation list or single annotation.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
item (dtlpy.entities.item.Item) – item entity
annotations (list or AnnotationCollection) – annotations list to convert
from_format (str) – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
to_format (str) – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
conversion_func (Callable) – Custom conversion service
- Returns:
the annotations
- convert_dataset(dataset, to_format: str, local_path: str, conversion_func=None, filters=None, annotation_filter=None)[source]¶
Convert entire dataset.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
dataset (dtlpy.entities.dataet.Dataset) – dataset entity
to_format (str) – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
local_path (str) – path to save the result to
conversion_func (Callable) – Custom conversion service
filters (dtlpy.entities.filters.Filters) – Filters entity or a dictionary containing filter parameters
annotation_filter (dtlpy.entities.filters.Filters) – Filter entity
- Returns:
the error log file path if there are errors and the coco json if the format is coco
- convert_directory(local_path: str, to_format: AnnotationFormat, from_format: AnnotationFormat, dataset, conversion_func=None)[source]¶
Convert annotation files in entire directory.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
local_path (str) – path to the directory
to_format (str) – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
from_format (str) – AnnotationFormat to convert from – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
dataset (dtlpy.entities.dataset.Dataset) – dataset entity
conversion_func (Callable) – Custom conversion service
- Returns:
the error log file path if there are errors
- convert_file(to_format: str, from_format: str, file_path: str, save_locally: bool = False, save_to: Optional[str] = None, conversion_func=None, item=None, pbar=None, upload: bool = False, **_)[source]¶
Convert file containing annotations.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
to_format (str) – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
from_format (str) – AnnotationFormat to convert from – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
file_path (str) – path of the file to convert
pbar (tqdm) – tqdm object that follows the work (progress bar)
upload (bool) – if True upload
save_locally (bool) – If True, save locally
save_to (str) – path to save the result to
conversion_func (Callable) – Custom conversion service
item (dtlpy.entities.item.Item) – item entity
- Returns:
annotation list, errors
- static custom_format(annotation, conversion_func, i_annotation=None, annotations=None, from_format=None, item=None, **_)[source]¶
Custom convert function.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation (dtlpy.entities.annotation.Annotation or dict) – annotations to convert
conversion_func (Callable) – Custom conversion service
i_annotation (int) – annotation index
annotations (list) – list of annotations
param str from_format: AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP :param dtlpy.entities.item.Item item: item entity :return: converted Annotation
- from_coco(annotation, **kwargs)[source]¶
Convert from COCO format to DATALOOP format. Use this as conversion_func param for functions that ask for this param.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation – annotations to convert
kwargs – additional params
- Returns:
converted Annotation entity
- Return type:
- static from_voc(annotation, **_)[source]¶
Convert from VOC format to DATALOOP format. Use this as conversion_func for functions that ask for this param.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation – annotations to convert
- Returns:
converted Annotation entity
- Return type:
- from_yolo(annotation, item=None, **kwargs)[source]¶
Convert from YOLO format to DATALOOP format. Use this as conversion_func param for functions that ask for this param.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation – annotations to convert
item (dtlpy.entities.item.Item) – item entity
kwargs – additional params
- Returns:
converted Annotation entity
- Return type:
- save_to_file(save_to, to_format, annotations, item=None)[source]¶
Save annotations to a file.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
save_to (str) – path to save the result to
to_format – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
annotations (list) – annotation list to convert
item (dtlpy.entities.item.Item) – item entity
- static to_coco(annotation, item=None, **_)[source]¶
Convert from DATALOOP format to COCO format. Use this as conversion_func param for functions that ask for this param.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation (dtlpy.entities.annotation.Annotation or dict) – annotations to convert
item (dtlpy.entities.item.Item) – item entity
**_ –
additional params
- Returns:
converted Annotation
- Return type:
- static to_voc(annotation, item=None, **_)[source]¶
Convert from DATALOOP format to VOC format. Use this as conversion_func param for functions that ask for this param.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation (dtlpy.entities.annotation.Annotation or dict) – annotations to convert
item (dtlpy.entities.item.Item) – item entity
**_ –
additional params
- Returns:
converted Annotation
- Return type:
- to_yolo(annotation, item=None, **_)[source]¶
Convert from DATALOOP format to YOLO format. Use this as conversion_func param for functions that ask for this param.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
annotation (dtlpy.entities.annotation.Annotation or dict) – annotations to convert
item (dtlpy.entities.item.Item) – item entity
**_ –
additional params
- Returns:
converted Annotation
- Return type:
- upload_local_dataset(from_format: AnnotationFormat, dataset, local_items_path: Optional[str] = None, local_labels_path: Optional[str] = None, local_annotations_path: Optional[str] = None, only_bbox: bool = False, filters=None, remote_items=None)[source]¶
Convert and upload local dataset to dataloop platform.
Prerequisites: You must be an owner or developer to use this method.
- Parameters:
from_format (str) – AnnotationFormat to convert to – AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.VOC, AnnotationFormat.DATALOOP
dataset (dtlpy.entities.dataset.Dataset) – dataset entity
local_items_path (str) – path to items to upload
local_annotations_path (str) – path to annotations to upload
local_labels_path (str) – path to labels to upload
only_bbox (bool) – only for coco datasets, if True upload only bbox
filters (dtlpy.entities.filters.Filters) – Filters entity or a dictionary containing filter parameters
remote_items (list) – list of the items to upload
- Returns:
the error log file path if there are errors