File size: 6,115 Bytes
82e7434 52527db 82e7434 f33b237 82e7434 41c8d05 82e7434 8d686db 82e7434 8d686db 82e7434 ffc83f8 82e7434 8d686db 82e7434 7cbbca1 82e7434 7cbbca1 82e7434 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
---
pipeline_tag: any-to-any
library_name: transformers
tags:
- text-to-image
- image-editing
- image-understanding
- vision-language
- multimodal
- autoregressive
- unified-model
---
## π UniPic2-SD3.5M-Kontext-2B
<div align="center">
<img src="skywork-logo.png" alt="Skywork Logo" width="500">
</div>
<p align="center">
<a href="https://github.com/SkyworkAI/UniPic">
<img src="https://img.shields.io/badge/GitHub-UniPic-blue?logo=github" alt="GitHub Repo">
</a>
<a href="https://github.com/SkyworkAI/UniPic/stargazers">
<img src="https://img.shields.io/github/stars/SkyworkAI/UniPic?style=social" alt="GitHub Stars">
</a>
<a href="https://github.com/SkyworkAI/UniPic/network/members">
<img src="https://img.shields.io/github/forks/SkyworkAI/UniPic?style=social" alt="GitHub Forks">
</a>
</p>
## π Introduction
**UniPic2-SD3.5M-Kontext-2B** is a 2B-parameter post-trained model built on the SD3.5-Medium family. It focuses on text-to-image generation and image editing, delivering strong quality with a fast generation speed. It runs smoothly on a single 16 GB consumer GPU.
<div align="center"> <img src="teaser.png" alt="Model Teaser" width="720"> </div>
## π Benchmarks
**UniPic2-SD3.5M-Kontext-2B** w/o GRPO achieves competitive results across a variety of vision-language tasks:
| Task | Score |
|--------------------|--------|
| π§ **GenEval** | 0.83 |
| πΌοΈ **DPG-Bench** | 83.7 |
| βοΈ **GEditBench-EN** | 6.31 |
| π§ͺ **ImgEdit-Bench** | 3.95 |
## π§ Usage
### 1. Clone the Repository
```bash
git clone https://github.com/SkyworkAI/UniPic
cd UniPic
```
### 2. Set Up the Environment
```bash
conda create -n unipic python=3.10.14
conda activate unipic
pip install -r requirements.txt
```
### 3.Text-to-Image Generation
```bash
import torch
from PIL import Image
from unipicv2.pipeline_stable_diffusion_3_kontext import StableDiffusion3KontextPipeline
from unipicv2.transformer_sd3_kontext import SD3Transformer2DKontextModel
from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
from transformers import CLIPTextModelWithProjection, CLIPTokenizer, T5EncoderModel, T5TokenizerFast
# Load model components
pretrained_model_name_or_path = "/path/to/unipicv2_sd_3_5m_kontext"
transformer = SD3Transformer2DKontextModel.from_pretrained(
pretrained_model_name_or_path, subfolder="transformer", torch_dtype=torch.bfloat16).cuda()
vae = AutoencoderKL.from_pretrained(
pretrained_model_name_or_path, subfolder="vae", torch_dtype=torch.bfloat16).cuda()
# Load text encoders
text_encoder = CLIPTextModelWithProjection.from_pretrained(
pretrained_model_name_or_path, subfolder="text_encoder", torch_dtype=torch.bfloat16).cuda()
tokenizer = CLIPTokenizer.from_pretrained(pretrained_model_name_or_path, subfolder="tokenizer")
text_encoder_2 = CLIPTextModelWithProjection.from_pretrained(
pretrained_model_name_or_path, subfolder="text_encoder_2", torch_dtype=torch.bfloat16).cuda()
tokenizer_2 = CLIPTokenizer.from_pretrained(pretrained_model_name_or_path, subfolder="tokenizer_2")
text_encoder_3 = T5EncoderModel.from_pretrained(
pretrained_model_name_or_path, subfolder="text_encoder_3", torch_dtype=torch.bfloat16).cuda()
tokenizer_3 = T5TokenizerFast.from_pretrained(pretrained_model_name_or_path, subfolder="tokenizer_3")
scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(pretrained_model_name_or_path, subfolder="scheduler")
# Create pipeline
pipeline = StableDiffusion3KontextPipeline(
transformer=transformer, vae=vae,
text_encoder=text_encoder, tokenizer=tokenizer,
text_encoder_2=text_encoder_2, tokenizer_2=tokenizer_2,
text_encoder_3=text_encoder_3, tokenizer_3=tokenizer_3,
scheduler=scheduler)
# Generate image
image = pipeline(
prompt='a pig with wings and a top hat flying over a happy futuristic scifi city',
negative_prompt='',
height=512, width=384,
num_inference_steps=50,
guidance_scale=3.5,
generator=torch.Generator(device=transformer.device).manual_seed(42)
).images[0]
image.save("text2image.png")
```
### 4. Image Editing
The image editing feature within this unified model is an exploratory module at the forefront of research. And it is not yet production-ready.
```bash
# Load and preprocess image
def fix_longer_edge(x, image_size, factor=32):
w, h = x.size
if w >= h:
target_w = image_size
target_h = h * (target_w / w)
target_h = round(target_h / factor) * factor
else:
target_h = image_size
target_w = w * (target_h / h)
target_w = round(target_w / factor) * factor
x = x.resize(size=(target_w, target_h))
return x
image = Image.open("text2image.png")
image = fix_longer_edge(image, image_size=512)
negative_prompt = "blurry, low quality, low resolution, distorted, deformed, broken content, missing parts, damaged details, artifacts, glitch, noise, pixelated, grainy, compression artifacts, bad composition, wrong proportion, incomplete editing, unfinished, unedited areas."
# Edit image
edited_image = pipeline(
image=image,
prompt="remove the pig's hat",
negative_prompt=negative_prompt,
height=image.height, width=image.width,
num_inference_steps=50,
guidance_scale=3.5,
generator=torch.Generator(device=transformer.device).manual_seed(42)
).images[0]
edited_image.save("image_editing.png")
```
## π License
This model is released under the MIT License.
## Citation
If you use Skywork-UniPic in your research, please cite:
```
@misc{wang2025skyworkunipicunifiedautoregressive,
title={Skywork UniPic: Unified Autoregressive Modeling for Visual Understanding and Generation},
author={Peiyu Wang and Yi Peng and Yimeng Gan and Liang Hu and Tianyidan Xie and Xiaokun Wang and Yichen Wei and Chuanxin Tang and Bo Zhu and Changshi Li and Hongyang Wei and Eric Li and Xuchen Song and Yang Liu and Yahui Zhou},
year={2025},
eprint={2508.03320},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2508.03320},
}
``` |