Shortcuts

mmagic.datasets.basic_conditional_dataset

Module Contents

Classes

BasicConditionalDataset

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

class mmagic.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)[源代码]

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/main/mmcls/datasets/base_dataset.py) # noqa and CustomDataset (https://github.com/open- mmlab/mmclassification/blob/main/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.

参数
  • 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[源代码]

The prefix of images.

property CLASSES[源代码]

Return all categories names.

property class_to_idx[源代码]

Map mapping class name to class index.

返回

mapping from class name to class index.

返回类型

dict

_find_samples(file_backend)[源代码]

find samples from data_prefix.

load_data_list()[源代码]

Load image paths and gt_labels.

is_valid_file(filename: str) bool[源代码]

Check if a file is a valid sample.

get_gt_labels()[源代码]

Get all ground-truth labels (categories).

返回

categories for all images.

返回类型

np.ndarray

get_cat_ids(idx: int) List[int][源代码]

Get category id by index.

参数

idx (int) – Index of data.

返回

Image category of specified index.

返回类型

cat_ids (List[int])

_compat_classes(metainfo, classes)[源代码]

Merge the old style classes arguments to metainfo.

full_init()[源代码]

Load annotation file and set BaseDataset._fully_initialized to True.

__repr__()[源代码]

Print the basic information of the dataset.

返回

Formatted string.

返回类型

str

extra_repr() List[str][源代码]

The extra repr information of the dataset.

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.