Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 9 min read How-to mediumAdept

Fine-Tune a Semantic Segmentation Model with a Custom Dataset

SegFormer, a hierarchical Transformer encoder with a lightweight MLP decoder, can be fine-tuned for semantic segmentation of sidewalk images for a delivery robot using Hugging Face transformers and datasets. The walkthrough loads the segments/sidewalk-semantic dataset, applies on-the-fly preprocessing with SegformerImageProcessor and ColorJitter augmentation, and fine-tunes the 14MB B0 variant with the Trainer API (lr 6e-5, batch size 2, 50 epochs). Evaluation uses mean IoU, which requires upsampling the model's quarter-resolution logits to label size. Inference follows the same pattern of bilinear interpolation plus argmax, and the model is pushed to the Hub with an auto-generated model card.

Assumes: PyTorch basicsPythonimage classification concepts

Related posts

  • Universal Image Segmentation with Mask2Former and OneFormer

    Hugging Face mediumAdept

    Instance, semantic and panoptic segmentation have converged on "universal" architectures that treat every task as binary mask classification rather than per-pixel classification, a line running from DETR through MaskFormer to Mask2Former. Mask2Former passes backbone features through a pixel decoder and uses a Transformer decoder to turn queries into mask and class predictions, but still needs separate training per task. OneFormer adds a text encoder conditioned on the task, so a single panoptic training run matches state of the art on all three tasks, at the cost of extra latency. Code shows panoptic inference and post-processing with Mask2Former in 🤗 transformers, plus the class changes needed to fine-tune from MaskFormer notebooks.

  • Timm ❤️ Transformers: Use any timm model with transformers

    Hugging Face mediumAdept

    TimmWrapper lets any timm vision model load through Hugging Face transformers' Auto classes and pipeline API. That makes architectures with no native transformers implementation, like MobileNetV4, usable with the standard tooling. Code examples cover pipeline inference, a Gradio demo, 8-bit quantization with bitsandbytes (346 MB to 88 MB, about 75% smaller, with near-identical predictions), Trainer-based fine-tuning and LoRA via PEFT (0.77% of parameters trainable), and torch.compile benchmarking. Fine-tuned models round-trip back into timm via the Hub with timm.create_model.

  • Deploy Hugging Face models easily with Amazon SageMaker

    Hugging Face mediumAdept

    Hugging Face Inference Deep Learning Containers and the SageMaker Hugging Face Inference Toolkit let Transformers models be deployed as SageMaker endpoints with a few lines of Python, using transformers pipelines for zero-code pre- and post-processing. Models can be deployed straight after a SageMaker training job via the Estimator, from a model.tar.gz in S3 via HuggingFaceModel's model_data, or directly from the Model Hub by setting the HF_MODEL_ID and HF_TASK environment variables. Requests use an `inputs` key plus optional pipeline `parameters`, and custom inference code can override the defaults when needed.

  • Hosting your Models and Datasets on Hugging Face Spaces using Streamlit

    Hugging Face mediumAdept

    Streamlit apps can showcase Hugging Face models and datasets and be hosted on Hugging Face Spaces. The walkthrough recreates "Write with Transformer" using Streamlit widgets such as text_area, sidebar sliders and number_input to collect generation hyperparameters like temperature, top-k and top-p. It then visualizes a poetry dataset, loaded with 🤗 Datasets streaming, using st.dataframe, st.bar_chart and st.pyplot for seaborn/matplotlib plots. Deployment means dragging files into a Space, listing dependencies in requirements.txt, and matching the Streamlit version.

  • Open-sourcing Knowledge Distillation Code and Weights of SD-Small and SD-Tiny

    Hugging Face mediumAdept

    Segmind releases training code and weights for SD-Small and SD-Tiny, Stable Diffusion variants compressed by block-removal knowledge distillation that cut UNet parameters by 35% and 55% while keeping image fidelity close to the base model. The student is trained with three losses: the standard latent diffusion loss, an output-matching loss against the teacher (Realistic-Vision 4.0), and a per-block feature-level loss. Training used 1M LAION Art Aesthetic images scoring above 7.5. The distilled models run up to 2x faster at inference but are early-stage and weak at composition, so they work best fine-tuned or LoRA-trained on specific styles. A portrait fine-tune of SD-Tiny is included with its hyperparameters.

The quest for software engineering knowledge.

Look:
Layout: