In this article
Keep the original image mode, index-to-class mapping and exact target-value comparison.
Establish whether palette indices are labels
A segmentation dataset stores class identifiers in a palettized mask. Its colors make annotations easy to inspect, but the training target consists of indices. A photographic preprocessing path converts the mask to RGB and later treats color-channel values as labels. The result remains a valid picture while changing the target. Establish the producer’s index-to-class contract first: a palette image is not inherently a segmentation annotation, and its colors alone do not define class identity.
Keep the palette separate from pixel indices
The Pillow concepts guide explains mode P as pixel indices interpreted through a palette. Retain the numeric target independently of the display mapping. Use deliberately unusual colors in a diagnostic mask so accidental equality between an index and a color component cannot conceal conversion. Record the source mode, allowed class vocabulary and ignored-pixel rule before comparing arrays. Palette transparency and a dataset’s ignore label must not be assumed to express the same concept.
Inspect conversion before blaming interpolation
The Image reference says convert translates P pixels through their palette. An RGB result therefore has a different representation from the original index plane. Converting those colors back to a palette can create a new color-index assignment; it is not a documented inverse of the dataset’s class mapping. Keep visualization conversion on a separate branch, and never recover training labels from display colors unless an explicit, validated dataset decoder requires that representation.
Check the mode at the resize call
The Image reference specifically states that resize uses NEAREST for mode P, regardless of the requested resampling choice. It would be inaccurate to blame ordinary resize(P) for creating blended class values through bilinear interpolation. The path can change after conversion to RGB, where that protection no longer describes the input mode. Inspect the actual mode at the operation, not only the file extension or an earlier loader variable. Nearest-neighbor selection preserves selected values but can still change thin regions and spatial boundaries.
Verify the complete target preparation path
Construct a controlled mask with known class indices, an ignored region and a palette unrelated to those indices. Capture the target after loading, conversion, resize, serialization and reload. Before resizing, compare the index plane exactly. After resizing, compare with the independently specified nearest-neighbor target and the intended image-to-mask geometry. Check vocabulary membership and ignored-pixel handling as separate assertions; a class histogram alone cannot detect a displaced region. Include a broken RGB-label path that the checker must reject. No image conversion or training experiment was executed here.
Preserve the label contract beyond a plausible picture
ADE20K mask conventions describe dataset-specific semantic and instance decoding. EXIF coordinate handling addresses transformations shared by images and annotations. This check instead follows the P-mode index plane through a generic preparation stack. Acceptance requires the final target to retain the declared class semantics and geometry. A visually attractive overlay is useful evidence for review, but cannot replace exact target and ignore-mask comparisons or justify silently inventing a new class vocabulary.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.