datumaro.components.dataset#
Functions
|
Classes
|
Represents a dataset, contains metainfo about labels and dataset items. |
|
|
|
- class datumaro.components.dataset.Dataset(source: IDataset | None = None, *, infos: Dict[str, Any] | None = None, categories: Dict[AnnotationType, Categories] | None = None, media_type: Type[MediaElement] | None = None, ann_types: Set[AnnotationType] | None = None, env: Environment | None = None)[source]#
Bases:
IDataset
Represents a dataset, contains metainfo about labels and dataset items. Provides iteration and access options to dataset elements.
By default, all operations are done lazily, it can be changed by modifying the eager property and by using the eager_mode context manager.
Dataset is supposed to have a single media type for its items. If the dataset is filled manually or from extractors, and media type does not match, an error is raised.
- classmethod from_iterable(iterable: ~typing.Iterable[~datumaro.components.dataset_base.DatasetItem], infos: ~typing.Dict[str, ~typing.Any] | None = None, categories: ~typing.Dict[~datumaro.components.annotation.AnnotationType, ~datumaro.components.annotation.Categories] | ~typing.List[str] | None = None, *, env: ~datumaro.components.environment.Environment | None = None, media_type: ~typing.Type[~datumaro.components.media.MediaElement] = <class 'datumaro.components.media.Image'>, ann_types: ~typing.Set[~datumaro.components.annotation.AnnotationType] | None = []) Dataset [source]#
Creates a new dataset from an iterable object producing dataset items - a generator, a list etc. It is a convenient way to create and fill a custom dataset.
- Parameters:
iterable – An iterable which returns dataset items
infos – A dictionary of the dataset specific information
categories – A simple list of labels or complete information about labels. If not specified, an empty list of labels is assumed.
media_type – Media type for the dataset items. If the sequence contains items with mismatching media type, an error is raised during caching
env – A context for plugins, which will be used for this dataset. If not specified, the builtin plugins will be used.
- Returns:
A new dataset with specified contents
- Return type:
dataset
- classmethod from_extractors(*sources: IDataset, env: Environment | None = None, merge_policy: str = 'exact') Dataset [source]#
Creates a new dataset from one or several `Extractor`s.
In case of a single input, creates a lazy wrapper around the input. In case of several inputs, merges them and caches the resulting dataset.
- Parameters:
sources – one or many input extractors
env – A context for plugins, which will be used for this dataset. If not specified, the builtin plugins will be used.
merge_policy – Policy on how to merge multiple datasets. Possible options are “exact”, “intersect”, and “union”.
- Returns:
A new dataset with contents produced by input extractors
- Return type:
dataset
- define_categories(categories: Dict[AnnotationType, Categories]) None [source]#
- get_subset(name) DatasetSubset [source]#
- subsets() Dict[str, DatasetSubset] [source]#
Enumerates subsets in the dataset. Each subset can be a dataset itself.
- categories() Dict[AnnotationType, Categories] [source]#
Returns metainfo about dataset labels.
- media_type() Type[MediaElement] [source]#
Returns media type of the dataset items.
All the items are supposed to have the same media type. Supposed to be constant and known immediately after the object construction (i.e. doesn’t require dataset iteration).
- ann_types() Set[AnnotationType] [source]#
Returns available task type from dataset annotation types.
- get(id: str, subset: str | None = None) DatasetItem | None [source]#
Provides random access to dataset items.
- filter(expr: str, *, filter_annotations: bool = False, remove_empty: bool = False) Dataset [source]#
- filter(filter_func: Callable[[DatasetItem], bool] | Callable[[DatasetItem, Annotation], bool], *, filter_annotations: bool = False, remove_empty: bool = False) Dataset
- update(source: DatasetPatch | IDataset | Iterable[DatasetItem]) Dataset [source]#
Updates items of the current dataset from another dataset or an iterable (the source). Items from the source overwrite matching items in the current dataset. Unmatched items are just appended.
If the source is a DatasetPatch, the removed items in the patch will be removed in the current dataset.
If the source is a dataset, labels are matched. If the labels match, but the order is different, the annotation labels will be remapped to the current dataset label order during updating.
Returns: self
- transform(method: str | Type[Transform], **kwargs) Dataset [source]#
Applies some function to dataset items.
Results are stored in-place. Modifications are applied lazily. Transforms are not allowed to change media type of dataset items.
- Parameters:
method – The transformation to be applied to the dataset. If a string is passed, it is treated as a plugin name, which is searched for in the dataset environment.
**kwargs – Parameters for the transformation
Returns: self
- run_model(model: Launcher | Type[ModelTransform], *, batch_size: int = 1, append_annotation: bool = False, num_workers: int = 0, **kwargs) Dataset [source]#
Applies a model to dataset items’ media and produces a dataset with media and annotations.
- Parameters:
model – The model to be applied to the dataset
batch_size – The number of dataset items processed simultaneously by the model
append_annotation – Whether append new annotation to existed annotations
num_workers – The number of worker threads to use for parallel inference. Set to 0 for single-process mode. Default is 0.
**kwargs – Parameters for the model
Returns: self
- get_patch() DatasetPatch [source]#
- property env: Environment#
- bind(path: str, format: str | None = None, *, options: Dict[str, Any] | None = None) None [source]#
Binds the dataset to a speific directory. Allows to set default saving parameters.
The following saves will be done to this directory by default and will use the saved parameters.
- export(save_dir: str, format: str | Type[Exporter], *, progress_reporter: ProgressReporter | None = None, error_policy: ExportErrorPolicy | None = None, **kwargs) None [source]#
Saves the dataset in some format.
- Parameters:
save_dir – The output directory
format – The desired output format. If a string is passed, it is treated as a plugin name, which is searched for in the dataset environment.
progress_reporter – An object to report progress
error_policy – An object to report format-related errors
**kwargs – Parameters for the format
- classmethod import_from(path: str, format: str | None = None, *, env: Environment | None = None, progress_reporter: ProgressReporter | None = None, error_policy: ImportErrorPolicy | None = None, **kwargs) Dataset [source]#
Creates a Dataset instance from a dataset on the disk.
- Parameters:
path (path - The input file or directory) –
format. (format - Dataset) – If a string is passed, it is treated as a plugin name, which is searched for in the env plugin context. If not set, will try to detect automatically, using the env plugin context.
set (env - A plugin collection. If not) –
used (the built-in plugins are) –
progress. (progress_reporter - An object to report) – Implies earger loading.
errors. (error_policy - An object to report format-related) – Implies earger loading.
format (**kwargs - Parameters for the) –
- static detect(path: str, *, env: Environment | None = None, depth: int = 2) str [source]#
Attempts to detect dataset format of a given directory.
This function tries to detect a single format and fails if it’s not possible. Check Environment.detect_dataset() for a function that reports status for each format checked.
- Parameters:
path – The directory to check
depth – The maximum depth for recursive search
env – A plugin collection. If not set, the built-in plugins are used
- datumaro.components.dataset.eager_mode(new_mode: bool = True, dataset: Dataset | None = None) None [source]#
- class datumaro.components.dataset.Annotation(*, id: int = 0, attributes: Dict[str, Any] = _Nothing.NOTHING, group: int = 0, object_id: int = -1)[source]#
Bases:
object
A base annotation class.
Derived classes must define the ‘_type’ class variable with a value from the AnnotationType enum.
Method generated by attrs for class Annotation.
- property type: AnnotationType#
- class datumaro.components.dataset.AnnotationType(value)[source]#
Bases:
IntEnum
An enumeration.
- unknown = 0#
- label = 1#
- mask = 2#
- points = 3#
- polygon = 4#
- polyline = 5#
- bbox = 6#
- cuboid_3d = 8#
- super_resolution_annotation = 9#
- depth_annotation = 10#
- ellipse = 11#
- hash_key = 12#
- feature_vector = 13#
- tabular = 14#
- rotated_bbox = 15#
- cuboid_2d = 16#
- class datumaro.components.dataset.DatasetBase(*, length: int | None = None, subsets: ~typing.Sequence[str] | None = None, media_type: ~typing.Type[~datumaro.components.media.MediaElement] = <class 'datumaro.components.media.Image'>, ann_types: ~typing.List[~datumaro.components.annotation.AnnotationType] | None = None, ctx: ~datumaro.components.contexts.importer.ImportContext | None = None)[source]#
Bases:
_DatasetBase
,CliPlugin
A base class for user-defined and built-in extractors. Should be used in cases, where SubsetBase is not enough, or its use makes problems with performance, implementation etc.
- exception datumaro.components.dataset.DatasetImportError[source]#
Bases:
DatumaroError
- class datumaro.components.dataset.DatasetItem(id: str, *, subset: str | None = None, media: str | MediaElement | None = None, annotations: List[Annotation] | None = None, attributes: Dict[str, Any] | None = None)[source]#
Bases:
object
- media: MediaElement | None#
- annotations: Annotations#
- class datumaro.components.dataset.DatasetItemStorageDatasetView(parent: DatasetItemStorage, infos: Dict[str, Any], categories: Dict[AnnotationType, Categories], media_type: Type[MediaElement] | None, ann_types: Set[AnnotationType] | None)[source]#
Bases:
IDataset
- class Subset(parent: DatasetItemStorageDatasetView, name: str)[source]#
Bases:
IDataset
- class datumaro.components.dataset.DatasetPatch(data: DatasetItemStorage, infos: Dict[str, Any], categories: Dict[AnnotationType, Categories], updated_items: Dict[Tuple[str, str], ItemStatus], updated_subsets: Dict[str, ItemStatus] | None = None)[source]#
Bases:
object
- class DatasetPatchWrapper(patch: DatasetPatch, parent: IDataset)[source]#
- property updated_subsets: Dict[str, ItemStatus]#
- class datumaro.components.dataset.DatasetStorage(source: IDataset | DatasetItemStorage, infos: Dict[str, Any] | None = None, categories: Dict[AnnotationType, Categories] | None = None, media_type: Type[MediaElement] | None = None, ann_types: Set[AnnotationType] | None = None)[source]#
Bases:
IDataset
- categories() Dict[AnnotationType, Categories] [source]#
Returns metainfo about dataset labels.
- define_categories(categories: Dict[AnnotationType, Categories])[source]#
- media_type() Type[MediaElement] [source]#
Returns media type of the dataset items.
All the items are supposed to have the same media type. Supposed to be constant and known immediately after the object construction (i.e. doesn’t require dataset iteration).
- ann_types() Set[AnnotationType] [source]#
Returns available task type from dataset annotation types.
- put(item: DatasetItem) None [source]#
- get(id: str, subset: str | None = None) DatasetItem | None [source]#
Provides random access to dataset items.
- subsets() Dict[str, IDataset] [source]#
Enumerates subsets in the dataset. Each subset can be a dataset itself.
- get_datasetitem_by_path(path: str) DatasetItem | None [source]#
- get_patch() DatasetPatch [source]#
- update(source: DatasetPatch | IDataset | Iterable[DatasetItem])[source]#
- class datumaro.components.dataset.DatasetSubset(parent: Dataset, name: str)[source]#
Bases:
IDataset
- class datumaro.components.dataset.Environment(use_lazy_import: bool = True)[source]#
Bases:
object
- property extractors: DatasetBaseRegistry#
- property importers: ImporterRegistry#
- property launchers: LauncherRegistry#
- property exporters: ExporterRegistry#
- property generators: GeneratorRegistry#
- property transforms: TransformRegistry#
- property validators: ValidatorRegistry#
- detect_dataset(path: str, depth: int = 1, rejection_callback: Callable[[str, RejectionReason, str], None] | None = None) List[str] [source]#
- classmethod merge(envs: Sequence[Environment]) Environment [source]#
- class datumaro.components.dataset.ExportContext(progress_reporter=None, error_policy=None)[source]#
Bases:
object
Method generated by attrs for class ExportContext.
- progress_reporter: ProgressReporter#
- error_policy: ExportErrorPolicy#
- class datumaro.components.dataset.ExportErrorPolicy[source]#
Bases:
object
- report_item_error(error: Exception, *, item_id: Tuple[str, str]) None [source]#
Allows to report a problem with a dataset item. If this function returns, the converter must skip the item.
- class datumaro.components.dataset.Exporter(extractor: IDataset, save_dir: str, *, save_media: bool | None = None, image_ext: str | None = None, default_image_ext: str | None = None, save_dataset_meta: bool = False, save_hashkey_meta: bool = False, stream: bool = False, ctx: ExportContext | None = None)[source]#
Bases:
CliPlugin
- DEFAULT_IMAGE_EXT = None#
- class datumaro.components.dataset.IDataset[source]#
Bases:
object
- subsets() Dict[str, IDataset] [source]#
Enumerates subsets in the dataset. Each subset can be a dataset itself.
- categories() Dict[AnnotationType, Categories] [source]#
Returns metainfo about dataset labels.
- get(id: str, subset: str | None = None) DatasetItem | None [source]#
Provides random access to dataset items.
- media_type() Type[MediaElement] [source]#
Returns media type of the dataset items.
All the items are supposed to have the same media type. Supposed to be constant and known immediately after the object construction (i.e. doesn’t require dataset iteration).
- ann_types() List[AnnotationType] [source]#
Returns available task type from dataset annotation types.
- class datumaro.components.dataset.Image(size: Tuple[int, int] | None = None, ext: str | None = None, *args, **kwargs)[source]#
Bases:
MediaElement
[ndarray
]
- class datumaro.components.dataset.ImportContext(progress_reporter=None, error_policy=None)[source]#
Bases:
object
Method generated by attrs for class ImportContext.
- progress_reporter: ProgressReporter#
- error_policy: ImportErrorPolicy#
- class datumaro.components.dataset.ImportErrorPolicy[source]#
Bases:
object
- report_item_error(error: Exception, *, item_id: Tuple[str, str]) None [source]#
Allows to report a problem with a dataset item. If this function returns, the extractor must skip the item.
- class datumaro.components.dataset.ItemTransform(extractor: IDataset)[source]#
Bases:
Transform
- transform_item(item: DatasetItem) DatasetItem | None [source]#
Returns a modified copy of the input item.
Avoid changing and returning the input item, because it can lead to unexpected problems. Use wrap_item() or item.wrap() to simplify copying.
- class datumaro.components.dataset.LabelCategories(items: List[str] = _Nothing.NOTHING, label_groups: List[LabelGroup] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING)[source]#
Bases:
Categories
Method generated by attrs for class LabelCategories.
- class Category(name, parent: str = '', attributes: Set[str] = _Nothing.NOTHING)[source]#
Bases:
object
Method generated by attrs for class LabelCategories.Category.
- class LabelGroup(name, labels: List[str] = [], group_type: GroupType = GroupType.EXCLUSIVE)[source]#
Bases:
object
Method generated by attrs for class LabelCategories.LabelGroup.
- label_groups: List[LabelGroup]#
- classmethod from_iterable(iterable: Iterable[str | Tuple[str] | Tuple[str, str] | Tuple[str, str, List[str]]]) LabelCategories [source]#
Creates a LabelCategories from iterable.
- Parameters:
iterable –
This iterable object can be:
a list of str - will be interpreted as list of Category names
a list of positional arguments - will generate Categories with these arguments
Returns: a LabelCategories object
- class datumaro.components.dataset.Launcher(model_dir: str | None = None)[source]#
Bases:
CliPlugin
- preprocess(item: DatasetItem) Tuple[ndarray | Dict[str, ndarray], PrepInfo] [source]#
Preprocess single dataset item before launch()
There are two output types:
1. The output is np.ndarray. For example, it can be image data as np.ndarray with BGR format (H, W, C). In this step, you usually implement resizing, normalizing, or color channel conversion for your launcher (or model).
2. The output is Dict[str, np.ndarray]. For example, it can be image and text pairs. Therefore, this can be used for the model having multi modality for image and text inputs.
- infer(inputs: Dict[str, ndarray]) List[Dict[str, ndarray] | List[Dict[str, ndarray]]] [source]#
- infer(inputs: ndarray) List[Dict[str, ndarray] | List[Dict[str, ndarray]]]
- postprocess(pred: Dict[str, ndarray] | List[Dict[str, ndarray]], info: PrepInfo) List[Annotation] [source]#
- launch(batch: Sequence[DatasetItem], stack: bool = True) List[List[Annotation]] [source]#
Launch to obtain the inference outputs of items.
- Parameters:
inputs – batch of Datasetitems
stack – If true, launch inference for the stacked input for the batch-wise dimension Otherwise, launch inference for each input.
- Returns:
A list of annotation list. Each annotation list is mapped to the input
DatasetItem
. These annotation list are pseudo-labels obtained by the model inference.
- type_check(item: DatasetItem) bool [source]#
Check the media type of dataset item.
If False, the item is excluded from the input batch.
- class datumaro.components.dataset.MediaElement(crypter: ~datumaro.components.crypter.Crypter = <datumaro.components.crypter.NullCrypter object>, *args, **kwargs)[source]#
Bases:
Generic
[AnyData
]
- class datumaro.components.dataset.ModelTransform(extractor: IDataset, launcher: Launcher, batch_size: int = 1, append_annotation: bool = False, num_workers: int = 0)[source]#
Bases:
Transform
A transformation class for applying a model’s inference to dataset items.
This class takes an dataset, a launcher, and other optional parameters to transform the dataset item from the model outputs by the launcher. It can process items using multiple processes if specified, making it suitable for parallelized inference tasks.
- Parameters:
extractor – The dataset extractor to obtain items from.
launcher – The launcher responsible for model inference.
batch_size – The batch size for processing items. Default is 1.
append_annotation – Whether to append inference annotations to existing annotations. Default is False.
num_workers – The number of worker threads to use for parallel inference. Set to 0 for single-process mode. Default is 0.
- exception datumaro.components.dataset.MultipleFormatsMatchError(formats)[source]#
Bases:
DatasetImportError
Method generated by attrs for class MultipleFormatsMatchError.
- formats#
- exception datumaro.components.dataset.NoMatchingFormatsError[source]#
Bases:
DatasetImportError
- class datumaro.components.dataset.NullProgressReporter[source]#
Bases:
ProgressReporter
- iter(iterable: Iterable[T], *, total: int | None = None, desc: str | None = None) Iterable[T] [source]#
Traverses the iterable and reports progress simultaneously.
Starts and finishes the progress bar automatically.
- Parameters:
iterable – An iterable to be traversed
total – The expected number of iterations. If not provided, will try to use iterable.__len__.
desc – The status message
- Returns:
An iterable over elements of the input sequence
- split(count: int) Tuple[ProgressReporter] [source]#
Splits the progress bar into few independent parts. In case of 0 must return an empty tuple.
This class is supposed to manage the state of children progress bars and release of their resources, if necessary.
- class datumaro.components.dataset.ProgressReporter[source]#
Bases:
object
- Only one set of methods must be called:
start - report_status - finish
iter
split
This class is supposed to manage the state of children progress bars and release of their resources, if necessary.
- iter(iterable: Iterable[T], *, total: int | None = None, desc: str | None = None) Iterable[T] [source]#
Traverses the iterable and reports progress simultaneously.
Starts and finishes the progress bar automatically.
- Parameters:
iterable – An iterable to be traversed
total – The expected number of iterations. If not provided, will try to use iterable.__len__.
desc – The status message
- Returns:
An iterable over elements of the input sequence
- split(count: int) Tuple[ProgressReporter, ...] [source]#
Splits the progress bar into few independent parts. In case of 0 must return an empty tuple.
This class is supposed to manage the state of children progress bars and release of their resources, if necessary.
- class datumaro.components.dataset.StreamDataset(source: IDataset | None = None, *, infos: Dict[str, Any] | None = None, categories: Dict[AnnotationType, Categories] | None = None, media_type: Type[MediaElement] | None = None, ann_types: Set[AnnotationType] | None = None, env: Environment | None = None)[source]#
Bases:
Dataset
- classmethod from_extractors(*sources: IDataset, env: Environment | None = None, merge_policy: str = 'exact') Dataset [source]#
Creates a new dataset from one or several `Extractor`s.
In case of a single input, creates a lazy wrapper around the input. In case of several inputs, unifies them and caches the resulting dataset. We cannot apply regular dataset merge, since items list cannot be accessed.
- Parameters:
sources – one or many input extractors
env – A context for plugins, which will be used for this dataset. If not specified, the builtin plugins will be used.
merge_policy – Policy on how to merge multiple datasets. Possible options are “exact”, “intersect”, and “union”.
- Returns:
A new dataset with contents produced by input extractors
- Return type:
dataset
- class datumaro.components.dataset.StreamDatasetStorage(source: IDataset, infos: Dict[str, Any] | None = None, categories: Dict[AnnotationType, Categories] | None = None, media_type: Type[MediaElement] | None = None, ann_types: Set[AnnotationType] | None = None)[source]#
Bases:
DatasetStorage
- put(item: DatasetItem) None [source]#
- get(id: str, subset: str | None = None) DatasetItem | None [source]#
Provides random access to dataset items.
- property subset_names#
- subsets() Dict[str, IDataset] [source]#
Enumerates subsets in the dataset. Each subset can be a dataset itself.
- get_datasetitem_by_path(path: str) DatasetItem | None [source]#
- update(source: DatasetPatch | IDataset | Iterable[DatasetItem])[source]#
- categories() Dict[AnnotationType, Categories] [source]#
Returns metainfo about dataset labels.
- exception datumaro.components.dataset.StreamedItemError[source]#
Bases:
DatasetError
Method generated by attrs for class StreamedItemError.
- class datumaro.components.dataset.TabularCategories(items: List[Category] = _Nothing.NOTHING, *, attributes: Set[str] = _Nothing.NOTHING)[source]#
Bases:
Categories
Describes tabular data metainfo such as column names and types.
Method generated by attrs for class TabularCategories.
- class Category(name, dtype: Type[TableDtype], labels: Set[str | int] = _Nothing.NOTHING)[source]#
Bases:
object
Method generated by attrs for class TabularCategories.Category.
- classmethod from_iterable(iterable: Iterable[Tuple[str, Type[TableDtype]] | Tuple[str, Type[TableDtype], Set[str]]]) TabularCategories [source]#
Creates a TabularCategories from iterable.
- Parameters:
iterable – a list of (Category name, type) or (Category name, type, set of labels)
Returns: a TabularCategories object
- class datumaro.components.dataset.Transform(extractor: IDataset)[source]#
Bases:
DatasetBase
,CliPlugin
A base class for dataset transformations that change dataset items or their annotations.
- exception datumaro.components.dataset.UnknownFormatError(format)[source]#
Bases:
DatumaroError
Method generated by attrs for class UnknownFormatError.
- format#
- class datumaro.components.dataset.UserFunctionAnnotationsFilter(extractor: IDataset, filter_func: Callable[[DatasetItem, Annotation], bool], remove_empty: bool = False)[source]#
Bases:
ItemTransform
Filter annotations using a user-provided Python function.
- Parameters:
extractor – Datumaro Dataset to filter.
filter_func – A Python callable that takes DatasetItem and Annotation as its inputs and returns a boolean. If the return value is True, the Annotation will be retained. Otherwise, it is removed.
remove_empty – If True, DatasetItem without any annotations is removed after filtering its annotations. Otherwise, do not filter DatasetItem.
Example
This is an example of removing bounding boxes sized greater than 50% of the image size:
from datumaro.components.media import Image from datumaro.components.annotation import Annotation, Bbox
- def filter_func(item: DatasetItem, ann: Annotation) -> bool:
# If the annotation is not a Bbox, do not filter if not isinstance(ann, Bbox):
return False
h, w = item.media_as(Image).size image_size = h * w bbox_size = ann.h * ann.w
# Accept Bboxes smaller than 50% of the image size return bbox_size < 0.5 * image_size
- filtered = UserFunctionAnnotationsFilter(
extractor=dataset, filter_func=filter_func)
# No bounding boxes with a size greater than 50% of their image filtered_items = [item for item in filtered]
- transform_item(item: DatasetItem) DatasetItem | None [source]#
Returns a modified copy of the input item.
Avoid changing and returning the input item, because it can lead to unexpected problems. Use wrap_item() or item.wrap() to simplify copying.
- class datumaro.components.dataset.UserFunctionDatasetFilter(extractor: IDataset, filter_func: Callable[[DatasetItem], bool])[source]#
Bases:
ItemTransform
Filter dataset items using a user-provided Python function.
- Parameters:
extractor – Datumaro Dataset to filter.
filter_func – A Python callable that takes a DatasetItem as its input and returns a boolean. If the return value is True, that DatasetItem will be retained. Otherwise, it is removed.
Example
This is an example of filtering dataset items with images larger than 1024 pixels:
from datumaro.components.media import Image
- def filter_func(item: DatasetItem) -> bool:
h, w = item.media_as(Image).size return h > 1024 or w > 1024
- filtered = UserFunctionDatasetFilter(
extractor=dataset, filter_func=filter_func)
# No items with an image height or width greater than 1024 filtered_items = [item for item in filtered]
- transform_item(item: DatasetItem) DatasetItem | None [source]#
Returns a modified copy of the input item.
Avoid changing and returning the input item, because it can lead to unexpected problems. Use wrap_item() or item.wrap() to simplify copying.
- class datumaro.components.dataset.XPathAnnotationsFilter(extractor: IDataset, xpath: str, remove_empty: bool = False)[source]#
Bases:
ItemTransform
- transform_item(item: DatasetItem) DatasetItem | None [source]#
Returns a modified copy of the input item.
Avoid changing and returning the input item, because it can lead to unexpected problems. Use wrap_item() or item.wrap() to simplify copying.
- class datumaro.components.dataset.XPathDatasetFilter(extractor: IDataset, xpath: str)[source]#
Bases:
ItemTransform
- transform_item(item: DatasetItem) DatasetItem | None [source]#
Returns a modified copy of the input item.
Avoid changing and returning the input item, because it can lead to unexpected problems. Use wrap_item() or item.wrap() to simplify copying.
- datumaro.components.dataset.contextmanager(func)[source]#
@contextmanager decorator.
Typical usage:
@contextmanager def some_generator(<arguments>):
<setup> try:
yield <value>
- finally:
<cleanup>
This makes this:
- with some_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup> try:
<variable> = <value> <body>
- finally:
<cleanup>
- datumaro.components.dataset.copy(x)[source]#
Shallow copy operation on arbitrary Python objects.
See the module’s __doc__ string for more info.
- datumaro.components.dataset.deepcopy(x, memo=None, _nil=[])[source]#
Deep copy operation on arbitrary Python objects.
See the module’s __doc__ string for more info.
- datumaro.components.dataset.overload(func)[source]#
Decorator for overloaded functions/methods.
In a stub file, place two or more stub definitions for the same function in a row, each decorated with @overload. For example:
@overload def utf8(value: None) -> None: … @overload def utf8(value: bytes) -> bytes: … @overload def utf8(value: str) -> bytes: …
In a non-stub file (i.e. a regular .py file), do the same but follow it with an implementation. The implementation should not be decorated with @overload. For example:
@overload def utf8(value: None) -> None: … @overload def utf8(value: bytes) -> bytes: … @overload def utf8(value: str) -> bytes: … def utf8(value):
# implementation goes here