Skip to content

Project Structure

ProjectStructure class

A ProjectStructure object represents project structure, without storing images and annotations itself. It maps each img/ann pair to a dictionary with arbitrary data (ia_data).

Iterable, with named tuple (project_name, ds_name, image_name, ia_data).

class ProjectStructure:
    def __init__(self, name):

Create empty ProjectStructure object.

  • name — project name.

Fields

datasets

Dictionary "dataset name" ⇒ DatasetStructure object.

name

Project name.

Properties

image_cnt

Count of img/ann pairs in the project.

Methods

__getitem__(self, item)

Get DatasetStructure object by name.

get_ia_data(self, ds_name, image_name, default=None)

Get ia_data dict linked with img/ann pair.

  • ds_name — dataset name.
  • image_name — image name.
  • default — default value.

update_ia_data(self, rhs)

Update ia_data dict linked with img/ann pair. Does nothing if the pair doesn't exist in the project.

  • rhs — object to update data dictionary with.

add_item(self, ds_name, image_name, ia_data)

Add new mapping from img/ann pair to ia_data dict. Replaces ia_data if the mapping already exists in the project.

  • ds_name — dataset name.
  • image_name — image name.
  • ia_data — dictionary with arbitrary data.

DatasetStructure class

A DatasetStructure object represents dataset structure, without storing images and annotations itself. It maps each img/ann pair to a dictionary with arbitrary data (ia_data).

Iterable, with tuple (image_name, ia_data).

class DatasetStructure:
    def __init__(self, name):

Create empty DatasetStructure object.

  • name — dataset name.

Properties

image_cnt

Count of img/ann pairs in the dataset.

Methods

__getitem__(self, item)

Get ia_data dict by image name.

get_ia_data(self, image_name, default=None)

Get ia_data dict linked with img/ann pair.

  • image_name — image name.
  • default — default value.

update_ia_data(self, rhs)

Update ia_data dict linked with img/ann pair. Does nothing if the pair doesn't exist in the dataset.

  • rhs — object to update data dictionary with.

ProjectFS class

A ProjectFS object represents structure of project in filesystem.

Iterable, with named tuple (project_name, ds_name, image_name, ia_data, img_path, ann_path).

class ProjectFS:
    def __init__(self, root_path, pr_structure):

Create a ProjectFS object from ProjectStructure.

  • root_path — project root path (doesn't include project name).
  • pr_structure — a ProjectStructure object.

Fields

pr_structure

A ProjectStructure object.

Properties

image_cnt

Count of img/ann pairs in the project.

project_path

Path to project directory (includes project name).

Methods

ann_path(self, ds_name, image_name)

Get path to annotation (JSON file).

  • ds_name — dataset name.
  • image_name — image name.

img_path(self, ds_name, image_name)

Get path to image file. Image path may be determined only if ia_data contains field image_ext (e.g. {'image_ext': '.png'})

  • ds_name — dataset name.
  • image_name — image name.

make_dirs(self)

Create all required directories to store project files.

@classmethod from_disk(cls, root_path, project_name, by_annotations=False)

Read project structure from filesystem and create a ProjectFS object. Skip mismatched images or annotations.

  • root_path — project root path (doesn't include project name).
  • project_name — project name.
  • by_annotations — allow annotations without images (in that case corresponding image extensions will not be determined).

@classmethod split_dir_project(cls, project_dir_path)

Split path to project directory (includes project name) to project root path and project name.

ProjectWriterFS class

A ProjectWriterFS object helps to write project to disk when project structure is not determined before writing.

class ProjectWriterFS:
    def __init__(self, init_dir, project_name=None):

Create a ProjectWriterFS object.

  • init_dir — project directory path if project_name is None, project root path otherwise.
  • project_name — project name.

Methods

write_image(self, img_desc, free_name)

Write image with given image name.

  • img_descImageDescriptor object. Should contain loaded image data.
  • free_name — new image name. Must be unique within dataset, where dataset is determined by image descriptor.

copy_image(self, img_desc, free_name)

Copy image with given image name.

  • img_descImageDescriptor object.
  • free_name — new image name. Must be unique within dataset, where dataset is determined by image descriptor.

write_ann(self, img_desc, packed_ann, free_name)

Save annotation with given image name.

  • img_descImageDescriptor object for corresponding image.
  • packed_ann — annotation packed to write.
  • free_name — new image name. Must be unique within dataset, where dataset is determined by image descriptor.

write_meta(self, meta)

Save project meta.

  • metaProjectMeta object.