Implementation:OpenGVLab InternVL Segmentation Train
| Knowledge Sources | |
|---|---|
| Domains | Training, Segmentation, Distributed Systems |
| Last Updated | 2026-02-07 14:00 GMT |
Overview
Main training script for training semantic segmentation models using the MMSegmentation framework with InternVL-specific custom components.
Description
This script serves as the core training entry point for all InternVL segmentation experiments. The parse_args() function accepts CLI arguments for config file path, work directory, checkpoint loading/resuming, GPU configuration, random seed, deterministic mode, and distributed launcher settings. It supports auto-resume for automatically continuing from the latest checkpoint.
The main() function orchestrates the full training pipeline:
- Loads the MMSeg Config and applies CLI overrides
- Determines work directory (CLI > config > derived from config filename)
- Initializes distributed training via the chosen launcher (pytorch/slurm/mpi) or falls back to single-GPU mode
- Reverts SyncBatchNorm to standard BN for non-distributed (DP) training
- Sets up logging, environment info collection, and random seed initialization with optional deterministic mode
- Builds the segmentor model and datasets from config
- Saves checkpoint metadata (mmseg version, config, CLASSES, PALETTE)
- Calls train_segmentor() with validation support
The script imports mmcv_custom and mmseg_custom modules at the top level to trigger registration of InternVL-specific components (custom backbones, decode heads, dataset classes, optimizer constructors) with the MMSeg registries.
Usage
Use this script as the entry point for training segmentation models with InternVL backbones, invoked via dist_train.sh or slurm_train.sh shell scripts.
Code Reference
Source Location
- Repository: OpenGVLab_InternVL
- File: segmentation/train.py
- Lines: 1-220
Signature
def parse_args(): ...
def main(): ...
Import
# Standalone script:
# python segmentation/train.py <config> --work-dir <output_dir>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | str | Yes | Path to the MMSeg training config file |
| --work-dir | str | No | Directory for saving logs and model checkpoints |
| --load-from | str | No | Checkpoint to load initial weights from |
| --resume-from | str | No | Checkpoint to resume training from |
| --launcher | str | No | Distributed launcher: none/pytorch/slurm/mpi |
| --seed | int | No | Random seed for reproducibility |
| --deterministic | flag | No | Enable deterministic CUDNN operations |
| --auto-resume | flag | No | Auto-resume from latest checkpoint |
Outputs
| Name | Type | Description |
|---|---|---|
| work_dir | directory | Checkpoints, logs, and config dumps |
| checkpoints | .pth files | Model checkpoints with metadata |
| log_file | .log | Timestamped training log |
Usage Examples
Basic Usage
# Single-GPU training:
# python segmentation/train.py configs/intern_vit_6b.py --work-dir work_dirs/internvit
# Distributed training:
# bash dist_train.sh configs/intern_vit_6b.py 8
# Resume training:
# python segmentation/train.py configs/intern_vit_6b.py --resume-from work_dirs/latest.pth