Update README.md
Browse files
README.md
CHANGED
@@ -5,3 +5,93 @@ sana 1.6b finetuned on aesthetic images: https://imgsli.com/MzI0NTYy
|
|
5 |
|
6 |
|
7 |
![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63a2d82b528eba15b1392902/QDr0Kx941dTqhdBidDPJm.jpeg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
![image/jpeg](https://cdn-uploads.huggingface.co/production/uploads/63a2d82b528eba15b1392902/QDr0Kx941dTqhdBidDPJm.jpeg)
|
8 |
+
|
9 |
+
Inference: https://github.com/NVlabs/Sana
|
10 |
+
|
11 |
+
Example
|
12 |
+
```
|
13 |
+
import torch
|
14 |
+
from app.sana_pipeline import SanaPipeline
|
15 |
+
from torchvision.utils import save_image
|
16 |
+
|
17 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
18 |
+
generator = torch.Generator(device=device).manual_seed(42)
|
19 |
+
|
20 |
+
sana = SanaPipeline("configs/sana_config/1024ms/Sana_1600M_img1024_AdamW.yaml")
|
21 |
+
|
22 |
+
sana.from_pretrained("hf://Efficient-Large-Model/Sana_1600M_1024px/checkpoints/Sana_1600M_1024px.pth")
|
23 |
+
|
24 |
+
from PIL import Image
|
25 |
+
import numpy as np
|
26 |
+
import gc
|
27 |
+
|
28 |
+
def norm_ip(img, low, high):
|
29 |
+
img.clamp_(min=low, max=high)
|
30 |
+
img.sub_(low).div_(max(high - low, 1e-5))
|
31 |
+
return img
|
32 |
+
|
33 |
+
@torch.inference_mode()
|
34 |
+
def txt2img(prompts):
|
35 |
+
negative_prompt = "bad anatomy, extra limbs, low quality"
|
36 |
+
images = []
|
37 |
+
images.clear()
|
38 |
+
for i, prompt in enumerate(prompts):
|
39 |
+
with torch.no_grad():
|
40 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
41 |
+
generator = torch.Generator(device=device).manual_seed(42)#int(time.time()))
|
42 |
+
|
43 |
+
images_np = sana(
|
44 |
+
prompt=prompt,
|
45 |
+
negative_prompt = negative_prompt,
|
46 |
+
height=1280,
|
47 |
+
width=960,
|
48 |
+
guidance_scale=4.5,
|
49 |
+
pag_guidance_scale=1.5,
|
50 |
+
num_inference_steps=24,
|
51 |
+
generator=generator,
|
52 |
+
num_images_per_prompt=1,
|
53 |
+
)
|
54 |
+
images_norm = [
|
55 |
+
Image.fromarray(
|
56 |
+
norm_ip(img, -1, 1)
|
57 |
+
.mul(255)
|
58 |
+
.add_(0.5)
|
59 |
+
.clamp_(0, 255)
|
60 |
+
.permute(1, 2, 0)
|
61 |
+
.to("cpu", torch.uint8)
|
62 |
+
.numpy()
|
63 |
+
.astype(np.uint8)
|
64 |
+
)
|
65 |
+
for img in images_np
|
66 |
+
]
|
67 |
+
images += images_norm
|
68 |
+
#torch.cuda.empty_cache()
|
69 |
+
gc.collect()
|
70 |
+
return images
|
71 |
+
|
72 |
+
from diffusers.utils import make_image_grid
|
73 |
+
|
74 |
+
prompts = [
|
75 |
+
"A beautiful young woman with short hair, wearing tattered clothing revealing glimpses of her skin beneath the rips and tears; soft lighting highlights both beauty features like piercing eyes or full lips while also emphasizing vulnerability",
|
76 |
+
"A beautiful young girl with long flowing hair sitting gracefully in a traditional Japanese kimono adorned intricate patterns, her serene expression radiating elegance against an ethereal backdrop of cherry blossoms blooming under the soft glow at sunset",
|
77 |
+
"A mysterious encounter: a beautiful 20-something girl dressed elegantly but haunting-ly among ruined classical architecture is confrontational stance facing an awe-inspiringaurora-luminescent beast that seems poised for attack or affection",
|
78 |
+
"An elegant cyberpunk female character with neon-lit eyes in urban night setting under futuristic skyscrapers; wearing form-fitting armor adorned by sleek lines of glowing blue circuits along her body.",
|
79 |
+
"Charismatic, rotund frog tavern keeper in a lush swamp, Frothy amber beer in webbed hands, Dressed in rustic vest and breeches, Surroundings teeming with life, Realistic and fantasy style",
|
80 |
+
"Two young women standing together in a park setting during golden hour sunlight with lush greenery, wearing casual summer clothing like sundresses - one blonde woman has long hair and the other brunette wears glasses",
|
81 |
+
"A serene, golden hour seascape features turquoise waves lapping on white sands framed by distant cliffs as an ethereal young woman in ivory lace dress strolls barefoot alongshore with her magnificent pure-white steed. ",
|
82 |
+
"portrait of Egor Letov in his signature style - a rugged, intense gaze with piercing eyes set against weathered skin; unruly dark hair framing the face and partially obscuring one eye as if hiding something rebellious underneath its shadowing strands",
|
83 |
+
"A young woman poses for a self-portrait (selfie) wearing minimal clothing, showcasing her toned legs. The bedroom is cluttered with signs she had been partying the previous evening",
|
84 |
+
"Nina Dobrev in her 20’ as an e girl with youthful beauty accentuated by the outfit: oversized wet checkered shirt, black leather boots & red floral headscarf framing delicate features while exposing eyes and lips against lush greenery bathed golden sunlight",
|
85 |
+
"ink splashes, drips, surreal, a man standing on a dock in swampy wetlands, at a distance, moonlit, lonely",
|
86 |
+
"Four strong movers in matching uniforms stand proudly outside charming farmhouse holding packages for a new homeowner's arrival; they project confidence yet approachability.",
|
87 |
+
"A young girl with flowing hair sits astride a large green frog in the midst of heavy rain falling from an overcast sky painted across canvas using rich oil paints and loose brushstrokes that capture both motion. The scene is set outdoors on lush grass ",
|
88 |
+
"A crucified angel amidst a throng of inquisitors surrounding him; close-up detail focusing intensely upon the anguish and horror etched across their faces as they witness his crucifixion. The scene is dark with dramatic lighting emphasizing shadows ",
|
89 |
+
"A massive crowd of one thousand people fills Red Square in Moscow's heart; their faces are flushed with anger and excitement as they raise fists high above heads. Chanting slogans into the camera lens held aloft by a lone journalist amidst them all ",
|
90 |
+
"A beautiful young woman with flowing long hair in a braid, wearing tattered clothing revealing glimpses of her skin beneath the rips and tears; soft lighting highlights both beauty features like piercing eyes or full lips while also emphasizing vulnerability",
|
91 |
+
]
|
92 |
+
|
93 |
+
images= txt2img(prompts)
|
94 |
+
grid = make_image_grid(images, rows=4, cols=4)
|
95 |
+
#grid.show()
|
96 |
+
grid.save("grid1.png")
|
97 |
+
```
|