Reference for ultralytics/models/yolo/world/train.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/yolo/world/train.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.models.yolo.world.train.WorldTrainer
Bases: DetectionTrainer
A class to fine-tune a world model on a close-set dataset.
This trainer extends the DetectionTrainer to support training YOLO World models, which combine visual and textual features for improved object detection and understanding.
Attributes:
Name | Type | Description |
---|---|---|
clip |
module
|
The CLIP module for text-image understanding. |
text_model |
module
|
The text encoder model from CLIP. |
model |
WorldModel
|
The YOLO World model being trained. |
data |
dict
|
Dataset configuration containing class information. |
args |
dict
|
Training arguments and configuration. |
Examples:
>>> from ultralytics.models.yolo.world import WorldModel
>>> args = dict(model="yolov8s-world.pt", data="coco8.yaml", epochs=3)
>>> trainer = WorldTrainer(overrides=args)
>>> trainer.train()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
dict
|
Configuration for the trainer. |
DEFAULT_CFG
|
overrides
|
dict
|
Configuration overrides. |
None
|
_callbacks
|
list
|
List of callback functions. |
None
|
Source code in ultralytics/models/yolo/world/train.py
build_dataset
Build YOLO Dataset for training or validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img_path
|
str
|
Path to the folder containing images. |
required |
mode
|
str
|
|
'train'
|
batch
|
int
|
Size of batches, this is for |
None
|
Returns:
Type | Description |
---|---|
Dataset
|
YOLO dataset configured for training or validation. |
Source code in ultralytics/models/yolo/world/train.py
get_model
Return WorldModel initialized with specified config and weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
Dict | str
|
Model configuration. |
None
|
weights
|
str
|
Path to pretrained weights. |
None
|
verbose
|
bool
|
Whether to display model info. |
True
|
Returns:
Type | Description |
---|---|
WorldModel
|
Initialized WorldModel. |
Source code in ultralytics/models/yolo/world/train.py
preprocess_batch
Preprocess a batch of images and text for YOLOWorld training.
Source code in ultralytics/models/yolo/world/train.py
ultralytics.models.yolo.world.train.on_pretrain_routine_end
Callback to set up model classes and text encoder at the end of the pretrain routine.