File size: 1,012 Bytes
2afd9cb 1b51e35 1bba93b ff2cb17 1b51e35 1bba93b 1b51e35 ff2cb17 1bba93b ff2cb17 1b51e35 ff2cb17 | 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 | ---
{}
---
```
import os
import torch
if not os.path.exists("seed2"):
os.system("git clone https://huggingface.co/ontocord/seed2")
from diffusers import StableUnCLIPImg2ImgPipeline
from seed2.seed2_tokenizer import Seed2Tokenizer
tokenizer = None
pipe = None
torch.cuda.empty_cache()
pipe = StableUnCLIPImg2ImgPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-unclip', torch_dtype=torch.float16)
pipe = pipe.to('cuda')
tokenizer = Seed2Tokenizer.from_pretrained("seed2", torch_dtype=torch.float16).to('cuda')
if not os.path.exists("cat.jpg"):
os.system("wget https://images.unsplash.com/photo-1574158622682-e40e69881006?w=300 -O cat.jpg")
tokens = tokenizer.encode_image("cat.jpg")
print (tokens)
image_embeds = tokenizer.model.get_codebook_entry(tokens)
print (image_embeds)
import time
t = time.time()
image = tokenizer.decode(pipe, tokens)[0] # this is using a fixed latent initalized by the model, so a call with the same tokens will produce the same image
print (time.time()-t)
image
```
|