Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:OpenGVLab InternVL ADE20KDataset

From Leeroopedia
Revision as of 16:14, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/OpenGVLab_InternVL_ADE20KDataset.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Segmentation, Dataset, Evaluation
Last Updated 2026-02-07 14:00 GMT

Overview

Custom ADE20K dataset class for semantic segmentation that extends MMSegmentation's CustomDataset with 150-class definitions, color palettes, few-shot subset sampling, and result formatting utilities.

Description

ADE20KDataset extends CustomDataset and is force-registered with the MMSeg DATASETS registry (overriding any existing registration). It defines all 150 ADE20K semantic classes (from "wall" to "flag") with corresponding PALETTE RGB color codes for visualization. The dataset uses fixed suffixes (.jpg for images, .png for segmentation maps) and sets reduce_zero_label=True because ADE20K uses 0 for background which is excluded from the 150 categories.

A key extension is the max_image_num parameter: when specified, the dataset randomly shuffles img_infos and truncates to the given count, enabling few-shot segmentation experiments where only a fraction of training data is used.

The results2img() method writes segmentation predictions as PNG files, adding 1 to all predictions to re-align with the original ADE20K label convention (0-150 instead of 0-149). The format_results() method orchestrates result formatting for standard ADE20K evaluation.

Usage

Use this dataset class in MMSegmentation configs for ADE20K semantic segmentation training and evaluation, including few-shot experiments with limited training data.

Code Reference

Source Location

Signature

@DATASETS.register_module(force=True)
class ADE20KDataset(CustomDataset):
    CLASSES = ('wall', 'building', 'sky', ...)  # 150 classes
    PALETTE = [[120, 120, 120], ...]             # 150 RGB palettes
    def __init__(self, max_image_num=None, **kwargs): ...
    def results2img(self, results, imgfile_prefix, to_label_id, indices=None): ...
    def format_results(self, results, imgfile_prefix, to_label_id=True, indices=None): ...

Import

from mmseg_custom.datasets.ade import ADE20KDataset

I/O Contract

Inputs

Name Type Required Description
max_image_num int or None No If set, randomly selects this many images for few-shot training
**kwargs dict Yes Standard CustomDataset arguments (data_root, pipeline, etc.)

Outputs

Name Type Description
dataset ADE20KDataset Dataset instance yielding image/segmentation map pairs
result_files list[str] PNG file paths when format_results() is called

Usage Examples

Basic Usage

# In MMSegmentation config:
data = dict(
    train=dict(
        type='ADE20KDataset',
        data_root='data/ade/ADEChallengeData2016',
        img_dir='images/training',
        ann_dir='annotations/training',
        max_image_num=1000,  # Few-shot: use only 1000 images
        pipeline=train_pipeline
    )
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment