Shortcuts

mmedit.datasets.basic_conditional_dataset

Module Contents

Classes

BasicConditionalDataset

Custom dataset for conditional GAN. This class is based on the

class mmedit.datasets.basic_conditional_dataset.BasicConditionalDataset(ann_file: str = '', metainfo: Optional[dict] = None, data_root: str = '', data_prefix: Union[str, dict] = '', extensions: Sequence[str] = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm', '.tif'), lazy_init: bool = False, classes: Union[str, Sequence[str], None] = None, **kwargs)[source]

Bases: mmengine.dataset.BaseDataset

Custom dataset for conditional GAN. This class is based on the combination of BaseDataset (https://github.com/open- mmlab/mmclassification/blob/1.x/mmcls/datasets/base_dataset.py) # noqa and CustomDataset (https://github.com/open- mmlab/mmclassification/blob/1.x/mmcls/datasets/custom.py). # noqa.

The dataset supports two kinds of annotation format.

  1. A annotation file read by line (e.g., txt) is provided, and each line indicates a sample:

    The sample files:

    data_prefix/
    ├── folder_1
    │   ├── xxx.png
    │   ├── xxy.png
    │   └── ...
    └── folder_2
        ├── 123.png
        ├── nsdf3.png
        └── ...
    

    The annotation file (the first column is the image path and the second column is the index of category):

    folder_1/xxx.png 0
    folder_1/xxy.png 1
    folder_2/123.png 5
    folder_2/nsdf3.png 3
    ...
    

    Please specify the name of categories by the argument classes or metainfo.

  2. A dict-based annotation file (e.g., json) is provided, key and value indicate the path and label of the sample:

    The sample files:

    data_prefix/
    ├── folder_1
    │   ├── xxx.png
    │   ├── xxy.png
    │   └── ...
    └── folder_2
        ├── 123.png
        ├── nsdf3.png
        └── ...
    

    The annotation file (the key is the image path and the value column is the label):

    {
        "folder_1/xxx.png": [1, 2, 3, 4],
        "folder_1/xxy.png": [2, 4, 1, 0],
        "folder_2/123.png": [0, 9, 8, 1],
        "folder_2/nsdf3.png", [1, 0, 0, 2],
        ...
    }
    

    In this kind of annotation, labels can be any type and not restricted to an index.

  3. The samples are arranged in the specific way:

    data_prefix/
    ├── class_x
    │   ├── xxx.png
    │   ├── xxy.png
    │   └── ...
    │       └── xxz.png
    └── class_y
        ├── 123.png
        ├── nsdf3.png
        ├── ...
        └── asd932_.png
    

If the ann_file is specified, the dataset will be generated by the first two ways, otherwise, try the third way.

Parameters
  • ann_file (str) – Annotation file path. Defaults to ‘’.

  • metainfo (dict, optional) – Meta information for dataset, such as class information. Defaults to None.

  • data_root (str) – The root directory for data_prefix and ann_file. Defaults to ‘’.

  • data_prefix (str | dict) – Prefix for the data. Defaults to ‘’.

  • extensions (Sequence[str]) – A sequence of allowed extensions. Defaults to (‘.jpg’, ‘.jpeg’, ‘.png’, ‘.ppm’, ‘.bmp’, ‘.pgm’, ‘.tif’).

  • lazy_init (bool) – Whether to load annotation during instantiation. In some cases, such as visualization, only the meta information of the dataset is needed, which is not necessary to load annotation file. Basedataset can skip load annotations to save time by set lazy_init=False. Defaults to False.

  • **kwargs – Other keyword arguments in BaseDataset.

property img_prefix[source]

The prefix of images.

property CLASSES[source]

Return all categories names.

property class_to_idx[source]

Map mapping class name to class index.

Returns

mapping from class name to class index.

Return type

dict

_find_samples(file_backend)[source]

find samples from data_prefix.

load_data_list()[source]

Load image paths and gt_labels.

is_valid_file(filename: str) bool[source]

Check if a file is a valid sample.

get_gt_labels()[source]

Get all ground-truth labels (categories).

Returns

categories for all images.

Return type

np.ndarray

get_cat_ids(idx: int) List[int][source]

Get category id by index.

Parameters

idx (int) – Index of data.

Returns

Image category of specified index.

Return type

cat_ids (List[int])

_compat_classes(metainfo, classes)[source]

Merge the old style classes arguments to metainfo.

full_init()[source]

Load annotation file and set BaseDataset._fully_initialized to True.

__repr__()[source]

Print the basic information of the dataset.

Returns

Formatted string.

Return type

str

extra_repr() List[str][source]

The extra repr information of the dataset.

Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.