huu-ontocord commited on
Commit
1b51e35
·
verified ·
1 Parent(s): 9a4aa0b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +12 -5
README.md CHANGED
@@ -1,12 +1,18 @@
1
  ---
2
  {}
3
  ---
4
- ```# first git clone this repo
5
  import os
6
  import torch
7
  if not os.path.exists("seed2"):
8
  os.system("git clone https://huggingface.co/ontocord/seed2")
 
9
  from seed2.seed2_tokenizer import Seed2Tokenizer
 
 
 
 
 
10
  tokenizer = Seed2Tokenizer.from_pretrained("seed2", torch_dtype=torch.float16).to('cuda')
11
  if not os.path.exists("cat.jpg"):
12
  os.system("wget https://images.unsplash.com/photo-1574158622682-e40e69881006?w=300 -O cat.jpg")
@@ -14,8 +20,9 @@ tokens = tokenizer.encode_image("cat.jpg")
14
  print (tokens)
15
  image_embeds = tokenizer.model.get_codebook_entry(tokens)
16
  print (image_embeds)
17
- from diffusers import StableUnCLIPImg2ImgPipeline
18
- pipe = StableUnCLIPImg2ImgPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-unclip', torch_dtype=torch.float16)
19
- pipe = pipe.to('cuda')
20
- tokenizer.decode(pipe, tokens)[0]
 
21
  ```
 
1
  ---
2
  {}
3
  ---
4
+ ```
5
  import os
6
  import torch
7
  if not os.path.exists("seed2"):
8
  os.system("git clone https://huggingface.co/ontocord/seed2")
9
+ from diffusers import StableUnCLIPImg2ImgPipeline
10
  from seed2.seed2_tokenizer import Seed2Tokenizer
11
+ tokenizer = None
12
+ pipe = None
13
+ torch.cuda.empty_cache()
14
+ pipe = StableUnCLIPImg2ImgPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-unclip', torch_dtype=torch.float16)
15
+ pipe = pipe.to('cuda')
16
  tokenizer = Seed2Tokenizer.from_pretrained("seed2", torch_dtype=torch.float16).to('cuda')
17
  if not os.path.exists("cat.jpg"):
18
  os.system("wget https://images.unsplash.com/photo-1574158622682-e40e69881006?w=300 -O cat.jpg")
 
20
  print (tokens)
21
  image_embeds = tokenizer.model.get_codebook_entry(tokens)
22
  print (image_embeds)
23
+ import time
24
+ t = time.time()
25
+ 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
26
+ print (time.time()-t)
27
+ image
28
  ```