Domain Enhanced Arbitrary Image Style Transfer via Contrastive Learning (CAST)


We provide our PyTorch implementation of the paper “Domain Enhanced Arbitrary Image Style Transfer via Contrastive Learning”(SIGGRAPH 2022), which is a simple yet powerful model for arbitrary style transfer.

In this work, we tackle the challenging problem of arbitrary image style transfer using a novel style feature representation learning method. A suitable style representation, as a key component in image stylization tasks, is essential to achieve satisfactory results. Existing deep neural network based approaches achieve reasonable results with the guidance from second-order statistics such as Gram matrix of content features. However, they do not leverage sufficient style information, which results in artifacts such as local distortions and style inconsistency. To address these issues, we propose to learn style representation directly from image features instead of their second-order statistics, by analyzing the similarities and differences between multiple styles and considering the style distribution.

For details see the paper

Getting Started


Python 3.6 or above.

PyTorch 1.6 or above

For packages, see requirements.txt.

pip install requirements.txt


Clone the repo

git clone


Then put your content images in ./datasets/{datasets_name}/testA, and style images in ./datasets/{datasets_name}/testB.

Example directory hierarchy:

   |--- datasets
          |--- {datasets_name}
                |--- testA
                |--- testB
   Then, call --dataroot ./datasets/{datasets_name}


Train the CAST model:

coming soon ...


Test the CAST model:

python --dataroot ./datasets/{dataset_name} --name {model_name}

The pretrained model is saved at ./checkpoints/CAST_model/*.pth.

BaiduNetdisk: Check here (passwd:cast)

Google Drive: Check here


author = {Zhang, Yuxin and Tang, Fan and Dong, Weiming and Huang, Haibin and Ma, Chongyang and Lee, Tong-Yee and Xu, Changsheng},
title = {Domain Enhanced Arbitrary Image Style Transfer via Contrastive Learning},
booktitle = {ACM SIGGRAPH},
year = {2022}}


Please feel free to open an issue or contact us personally if you have questions, need help, or need explanations. Write to one of the following email addresses, and maybe put one other in the cc:

[email protected]


View Github