

SegFormer consists of a hierarchical Transformer encoder, and a lightweight all-MLP decoder head.
  [SegformerModel] is the hierarchical Transformer encoder (which in the paper is also referred to
  as Mix Transformer or MiT). [SegformerForSemanticSegmentation] adds the all-MLP decoder head on
  top to perform semantic segmentation of images. In addition, there's
  [SegformerForImageClassification] which can be used to - you guessed it - classify images. The
  authors of SegFormer first pre-trained the Transformer encoder on ImageNet-1k to classify images. Next, they throw
  away the classification head, and replace it by the all-MLP decode head. Next, they fine-tune the model altogether on
  ADE20K, Cityscapes and COCO-stuff, which are important benchmarks for semantic segmentation. All checkpoints can be
  found on the hub.
The quickest way to get started with SegFormer is by checking the example notebooks (which showcase both inference and
  fine-tuning on custom data). One can also check out the blog post introducing SegFormer and illustrating how it can be fine-tuned on custom data.
TensorFlow users should refer to this repository that shows off-the-shelf inference and fine-tuning.
One can also check out this interactive demo on Hugging Face Spaces
  to try out a SegFormer model on custom images.
SegFormer works on any input size, as it pads the input to be divisible by config.patch_sizes.
One can use [SegformerImageProcessor] to prepare images and corresponding segmentation maps
  for the model. Note that this image processor is fairly basic and does not include all data augmentations used in
  the original paper. The original preprocessing pipelines (for the ADE20k dataset for instance) can be found here. The most
  important preprocessing step is that images and segmentation maps are randomly cropped and padded to the same size,
  such as 512x512 or 640x640, after which they are normalized.
One additional thing to keep in mind is that one can initialize [SegformerImageProcessor] with
  reduce_labels set to True or False. In some datasets (like ADE20k), the 0 index is used in the annotated
  segmentation maps for background. However, ADE20k doesn't include the "background" class in its 150 labels.
  Therefore, reduce_labels is used to reduce all labels by 1, and to make sure no loss is computed for the
  background class (i.e. it replaces 0 in the annotated maps by 255, which is the ignore_index of the loss function
  used by [SegformerForSemanticSegmentation]). However, other datasets use the 0 index as
  background class and include this class as part of all labels. In that case, reduce_labels should be set to
  False, as loss should also be computed for the background class.
As most models, SegFormer comes in different sizes, the details of which can be found in the table below
  (taken from Table 7 of the original paper).