yarrow.yarrow_cls.YarrowDataset

class yarrow.yarrow_cls.YarrowDataset(info: Info, images: Optional[List[Image]] = None, annotations: Optional[List[Annotation]] = None, contributors: Optional[List[Contributor]] = None, confidential: Optional[List[Clearance]] = None, categories: Optional[List[Category]] = None, multilayer_images: Optional[List[MultilayerImage]] = None)

Bases: object

__init__(info: Info, images: Optional[List[Image]] = None, annotations: Optional[List[Annotation]] = None, contributors: Optional[List[Contributor]] = None, confidential: Optional[List[Clearance]] = None, categories: Optional[List[Category]] = None, multilayer_images: Optional[List[MultilayerImage]] = None) None

Entry point for a YarrowDataset, can be created empty of images or annotations. Use the appropriate functions add_annotations() and add_images() to insert elements in the object.

Example: ``` annot = Annotation(…)

yar_dataset = YarrowDataset(info=Info(…)) yar_dataset.add_annotation(annot) # This will take care of the image, categories and contributor

```

Args:

info (Info): images (List[Image], optional): Defaults to None. annotations (List[Annotation], optional): Defaults to None. contributors (List[Contributor], optional): Defaults to None. confidential (List[Clearance], optional): Defaults to None. categories (List[Category], optional): Defaults to None. multilayer_images (List[MultilayerImage], optional): Defaults to None.

Methods

__init__(info[, images, annotations, ...])

Entry point for a YarrowDataset, can be created empty of images or annotations.

add_annotation(annot)

YOU DO NOT NEED TO ADD IMAGE AFTER THIS.

add_annotations(annots)

DONT NEED TO ADD IMAGE AFTER THIS.

add_image(image)

Add an image and its confidential object if it exists Returns the

add_images(images)

Add an image list and its confidential objects if they exists and returns the actual images found in the yarrow in case they are already present.

add_multilayer_image(multilayer)

Add a multilayer image object, the returned multilayer object will be the one in the current YarrowDataset and the original will remain unchanged

add_multilayer_images(multilayer_list)

Adds a list of multilayer images and returns the actual multilayer images that are present in the dataset.

append(yarrow)

Appends another YarrowDataset to this dataset.

extend(yarrows)

Extends a YarrowDataset with a list of YarrowDatasets

from_yarrow(yarrow)

Constructor to transform a YarrowDataset_pydantic and replace all id links with direct object references.

get_split(split)

Returns a new dataset based on a split value.

parse_file(path, **kwargs)

parse_obj(obj, **kwargs)

parse_raw(raw, **kwargs)

pydantic([img_id, reset])

Returns the pydantic YarrowDataset with all elements object links replaced by id links.

set_split(split)

Assigns the value of split to all the images and multilayer images

add_annotation(annot: Annotation) Annotation

YOU DO NOT NEED TO ADD IMAGE AFTER THIS. Insertion is done in place If the annotation already exists in the dataset, it will not be added and this function will return the one found

Be careful, to overwrite metadata you should modify directly the object and not try to overwrite it

Args:

annot (Annotation)

Return:

(Annotation)

add_annotations(annots: List[Annotation]) List[Annotation]

DONT NEED TO ADD IMAGE AFTER THIS. Insertion is done in place

Args:

annots (List[Annotation])

Return:

(List[Annotation]). Returns the annotation that were added

add_image(image: Image) Image

Add an image and its confidential object if it exists Returns the

Args:

image (Image)

Return:

(Image)

add_images(images: List[Image]) List[Image]

Add an image list and its confidential objects if they exists and returns the actual images found in the yarrow in case they are already present. SHould preserve image order in the list but does not guarantee only unique images are present in the returned image list

Args:

images (List[Image])

Return:

(List[Images])

add_multilayer_image(multilayer: MultilayerImage) MultilayerImage

Add a multilayer image object, the returned multilayer object will be the one in the current YarrowDataset and the original will remain unchanged

Args:

multilayer (MultilayerImage): input multilayer image object

Returns:

MultilayerImage: A copy of the original multilayer image object contained in the current YarrowDataset

add_multilayer_images(multilayer_list: List[MultilayerImage]) List[MultilayerImage]

Adds a list of multilayer images and returns the actual multilayer images that are present in the dataset. The returned list will contain links to the objects in the current YarrowDataset

Args:

multilayer_list (List[MultilayerImage]): Input MultilayerImage list

Returns:

List[MultilayerImage]: MultilayerImage list with the current dataset objects linked

append(yarrow: YarrowDataset) None

Appends another YarrowDataset to this dataset. The resulting dataset is this object. The objects added will be the annotations, the multilayer_images and the images

Args:

yarrow (YarrowDataset): Input Yarrow to be merge

extend(yarrows: List[YarrowDataset]) None

Extends a YarrowDataset with a list of YarrowDatasets

Args:

yarrows (List[YarrowDataset]): List of YarrowDatasets, they will remain unchanged

classmethod from_yarrow(yarrow: YarrowDataset_pydantic) YarrowDataset

Constructor to transform a YarrowDataset_pydantic and replace all id links with direct object references. Be careful when using directly, it is better to use parse_*() functions and not this one directly.

Args:

yarrow (YarrowDataset_pydantic): _description_

Raises:

TypeError: If the input is not of correct type.

ValueError: Raised if an id link could not be resolved, ex: an annotation referenced a category but no category had a matching id

Returns:

YarrowDataset

get_split(split: str) YarrowDataset

Returns a new dataset based on a split value.

The returned YarrowDataset will copy all the internal elements, meaning modifications on the new YarrowDataset won’t impact the original YarrowDataset

Args:

split (str): The split to retrieve

Returns:

YarrowDataset: A copy of the current dataset containing only the elements linked to a given split value

pydantic(img_id: Optional[str] = None, reset: bool = False) YarrowDataset_pydantic

Returns the pydantic YarrowDataset with all elements object links replaced by id links. The returned object can then be used to serialize the dataset using dict() and json() functions following a pydantic behaviour. See pydantic and the BaseModel class to understand how it behaves.

Args:

img_id (str, optional): If supplied, this id will be given to all images in the dataset and reinstantiate their pydantic objects. Defaults to None. reset (bool, optional): If supplied, it will reset all the cached pydantic classes. Defaults to False

Returns:

YarrowDataset_pydantic

set_split(split: str) None

Assigns the value of split to all the images and multilayer images

Args:

split (str): Describes the split, used to set “train”/”validate”/”test” for example