Skip to content

LightlyTrain for fine-tuning DINO foundation models#1

Open
xiaoyachong wants to merge 6 commits into
mlexchange:mainfrom
xiaoyachong:main
Open

LightlyTrain for fine-tuning DINO foundation models#1
xiaoyachong wants to merge 6 commits into
mlexchange:mainfrom
xiaoyachong:main

Conversation

@xiaoyachong
Copy link
Copy Markdown
Collaborator

@xiaoyachong xiaoyachong commented May 11, 2026

I mimicked the mlex_dlsia_segmentation_prototype repository to create this one. LightlyTrain is a useful package for fine-tuning foundation models for instance, semantic, and panoptic segmentation. I utilized it for semantic segmentation in our segmentation application.

To fine-tune a LightlyTrain model, we first need to convert the Tiled data into a temporary data folder with the following structure:

my_data_dir
├── train
│   ├── images
│   │   ├── image0.jpg
│   │   └── image1.jpg
│   └── masks
│       ├── image0.png
│       └── image1.png
└── val
    ├── images
    │   ├── image2.jpg
    │   └── image3.jpg
    └── masks
        ├── image2.png
        └── image3.png

After the data is prepared, we can call lightly_train.train_semantic_segmentation to fine-tune the model:

import lightly_train

if __name__ == "__main__":
    lightly_train.train_semantic_segmentation(
        out="out/my_experiment",
        model="dinov3/vits16-eomt",
        data={
            "train": {
                "images": "my_data_dir/train/images",
                "masks": "my_data_dir/train/masks",
            },
            "val": {
                "images": "my_data_dir/val/images",
                "masks": "my_data_dir/val/masks",
            },
            "classes": {
                0: "sand",
                1: "air",
                2: "background",
                255: "unknown",
            },
            "ignore_classes": [255],
        },
    )

Once fine-tuning is complete, the fine-tuned model checkpoint is registered to MLflow.

Companion PRs:
mlex_highres: mlexchange/mlex_highres_segmentation#219
mlex_tomo: mlexchange/mlex_tomo_framework#18

@xiaoyachong xiaoyachong changed the title Lightly_train for fine-tuning foundation models LightlyTrain for fine-tuning foundation models May 11, 2026
@xiaoyachong xiaoyachong changed the title LightlyTrain for fine-tuning foundation models LightlyTrain for fine-tuning DINO foundation models May 11, 2026
@xiaoyachong xiaoyachong requested a review from taxe10 May 13, 2026 17:19
Copy link
Copy Markdown
Member

@taxe10 taxe10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks great! I left some minor comments. We should also add some unit tests to the repo.

Comment thread mlex_lightly/parameters.py Outdated
Comment thread mlex_lightly/parameters.py Outdated
Comment thread mlex_lightly/train.py Outdated
Comment thread mlex_lightly/train.py Outdated
Comment thread mlex_lightly/train.py
Comment thread uv.lock
Comment thread mlex_lightly/train.py Outdated
Comment thread mlex_lightly/wrapper.py Outdated
Comment thread mlex_lightly/wrapper.py Outdated
Comment thread README.md Outdated
@xiaoyachong
Copy link
Copy Markdown
Collaborator Author

PR looks great! I left some minor comments. We should also add some unit tests to the repo.

Thanks for your comments! I just addressed them and added pytest.

@xiaoyachong xiaoyachong requested a review from taxe10 May 18, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants