Official PyTorch implementation for the paper:
This repository contains code for source-free unsupervised domain adaptation (SFUDA) with the proposed OT score, including source model training, target adaptation, and OT-score-related feature/prototype utilities.
The OT score is a confidence score based on semi-discrete optimal transport. It is designed to estimate the reliability of target pseudo-labels in prototype-assisted source-free unsupervised domain adaptation.
This repository provides:
train_source.py: train the source model and save source checkpointstrain_target.py: adapt the target model from a trained source checkpointutils/ot_score_utils.py: OT score computation and feature/prototype utilities
.
├── train_source.py
├── train_target.py
├── environment.yaml
├── utils/
│ └── ot_score_utils.py
├── output/
└── README.md
Create the conda environment from environment.yaml:
conda env create -f environment.yaml
conda activate OTscoreIf you use a different environment name, for example DA, activate that environment consistently:
conda activate DAThis code assumes that --datadir contains both:
- Image folders referenced by the list files
- DomainNet list files, such as:
clipart_list.txt
real_list.txt
painting_list.txt
sketch_list.txt
Each list file should follow the format:
relative/or/absolute/image_path label_id
For example:
clipart/airplane/image_0001.jpg 0
clipart/bicycle/image_0002.jpg 1
In the commands below, replace:
/path/to/domainnet/
with your own dataset root directory.
To train a source model for one source-target task on DomainNet, run:
python train_source.py \
--dset domainnet \
--s 0 \
--t 1 \
--datadir "/path/to/domainnet/" \
--output outputBy default, this only trains the source model and does not run target-side testing.
To additionally run source-side testing after training, use:
python train_source.py \
--dset domainnet \
--s 0 \
--t 1 \
--datadir "/path/to/domainnet/" \
--output output \
--test_targetSource checkpoints will be saved to:
output/<dset>/<SourceInitial>/
source_F_<seed>.pt
source_B_<seed>.pt
source_C_<seed>.pt
For example:
output/domainnet/C/
source_F_2026.pt
source_B_2026.pt
source_C_2026.pt
After training the source model, run target adaptation with:
python train_target.py \
--dset domainnet \
--s 0 \
--t 1 \
--datadir "/path/to/domainnet/" \
--output_src output \
--output output \
--seed 2026The target adaptation script loads source checkpoints from:
<output_src>/<dset>/<SourceInitial>/source_*.pt
Target checkpoints will be saved to:
<output>/<dset>/<SourceInitial><TargetInitial>/
target_F_<seed>.pt
target_B_<seed>.pt
target_C_<seed>.pt
For example:
output/domainnet/CR/
target_F_2026.pt
target_B_2026.pt
target_C_2026.pt
A typical workflow is:
python train_source.py \
--dset domainnet \
--s 0 \
--t 1 \
--datadir "/path/to/domainnet/" \
--output output \
--seed 2026python train_target.py \
--dset domainnet \
--s 0 \
--t 1 \
--datadir "/path/to/domainnet/" \
--output_src output \
--output output \
--seed 2026The OT score and related feature/prototype utilities are implemented in:
utils/ot_score_utils.py
These utilities are used during target adaptation to compute confidence scores for pseudo-labeled target samples.
The OT score can be used for:
- identifying low-confidence target pseudo-labels
- reweighting target samples during adaptation
- providing a label-free proxy for target-domain performance
If you find this repository useful, please cite our paper:
@article{zhang2026otscore,
title={OT Score: An OT based Confidence Score for Prototype-Assisted Source Free Unsupervised Domain Adaptation},
author={Zhang, Yiming and Liu, Sitong and Cloninger, Alex},
journal={Transactions on Machine Learning Research},
year={2026}
}