SykoSLM commited on
Commit
1857212
·
verified ·
1 Parent(s): adaf617

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - diffusion
7
+ - text-to-image
8
+ - latent-diffusion
9
+ - pytorch
10
+ pipeline_tag: text-to-image
11
+ ---
12
+
13
+ # SykoDiffusion V1.0
14
+
15
+ İlk versiyon latent diffusion modelim. CLIP text encoder ve VAE kullanarak metinden görüntü üretir.
16
+
17
+ ## Model Detayları
18
+
19
+ | Özellik | Değer |
20
+ |---|---|
21
+ | Parametre | ~100M |
22
+ | Mimari | Latent Diffusion (U-Net) |
23
+ | Eğitim Verisi | CC3M (~100k görsel) |
24
+ | Eğitim Adımı | 20.000 step |
25
+ | Çözünürlük | 256×256 |
26
+ | Donanım | 2× NVIDIA T4 |
27
+
28
+ ## Kullanım
29
+
30
+ ```python
31
+ import torch
32
+ from diffusers import UNet2DConditionModel, AutoencoderKL, DDIMScheduler
33
+ from transformers import CLIPTextModel, CLIPTokenizer
34
+ from PIL import Image
35
+ import numpy as np
36
+
37
+ device = "cuda" if torch.cuda.is_available() else "cpu"
38
+
39
+ unet = UNet2DConditionModel.from_pretrained("SykoSLM/SykoDiffusion-V1.0").to(device).half()
40
+ vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse").to(device).half()
41
+ clip = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14").to(device).half()
42
+ tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14")
43
+ scheduler = DDIMScheduler(num_train_timesteps=1000, beta_start=0.00085,
44
+ beta_end=0.012, beta_schedule="scaled_linear", clip_sample=False)
45
+
46
+ @torch.no_grad()
47
+ def generate(prompt, steps=30, cfg=7.5, seed=42):
48
+ torch.manual_seed(seed)
49
+ tokens = tokenizer(prompt, padding="max_length", truncation=True, max_length=77, return_tensors="pt").to(device)
50
+ text_emb = clip(**tokens).last_hidden_state
51
+ neg_tokens = tokenizer("", padding="max_length", truncation=True, max_length=77, return_tensors="pt").to(device)
52
+ neg_emb = clip(**neg_tokens).last_hidden_state
53
+ emb = torch.cat([neg_emb, text_emb])
54
+ latents = torch.randn(1, 4, 32, 32, device=device, dtype=torch.float16)
55
+ scheduler.set_timesteps(steps)
56
+ for t in scheduler.timesteps:
57
+ pred = unet(torch.cat([latents]*2), t, encoder_hidden_states=emb).sample
58
+ neg_p, text_p = pred.chunk(2)
59
+ pred = neg_p + cfg * (text_p - neg_p)
60
+ latents = scheduler.step(pred, t, latents).prev_sample
61
+ image = vae.decode(latents / vae.config.scaling_factor).sample
62
+ image = (image.clamp(-1,1)+1)/2
63
+ image = (image[0].permute(1,2,0).cpu().float().numpy()*255).astype("uint8")
64
+ return Image.fromarray(image)
65
+
66
+ img = generate("a cat sitting on a chair")
67
+ img.save("output.png")
68
+ ```
69
+
70
+ ## Notlar
71
+
72
+ - Bu model deneysel bir ilk versiyondur, üretim kalitesi sınırlı olabilir.
73
+ - En iyi sonuç için `cfg` değerini 5–10 arasında deneyin.
74
+ - İngilizce prompt önerilir.
75
+
76
+ ## Geliştirici
77
+
78
+ [@SykoSLM](https://huggingface.co/SykoSLM)