Diffusers
Safetensors
PixCellPipeline
srikarym commited on
Commit
331d8b3
·
verified ·
1 Parent(s): f24b090

update readme

Browse files
Files changed (1) hide show
  1. README.md +16 -30
README.md CHANGED
@@ -68,39 +68,25 @@ from huggingface_hub import hf_hub_download
68
 
69
  # This is an example image we provide
70
  path = hf_hub_download(repo_id="StonyBrook-CVLab/PixCell-1024", filename="test_image.png")
71
- image = Image.open(path)
72
-
73
- # Extract UNI from random patches in the image
74
- n_patches = 1
75
- patches = []
76
- uni_emb = []
77
- for k in range(n_patches):
78
- # Extract random crop
79
- sz = pipeline.transformer.config.sample_size * pipeline.vae_scale_factor
80
-
81
- x1 = np.random.randint(0, image.size[0] - sz+1)
82
- y1 = np.random.randint(0, image.size[1] - sz+1)
83
- image_patch = image.crop((x1, y1, x1+sz, y1+sz))
84
- patches.append(image_patch)
85
- print("Extracted patch:", patches[-1].size)
86
-
87
- # Rearrange 1024x1024 image into 16 256x256 patches
88
- uni_patches = np.array(image_patch)
89
- uni_patches = einops.rearrange(uni_patches, '(d1 h) (d2 w) c -> (d1 d2) h w c', d1=4, d2=4)
90
-
91
- # Extract UNIs for each patch
92
- uni_images = torch.cat(
93
- [transform(Image.fromarray(x)).unsqueeze(0) for x in uni_patches],
94
- dim=0)
95
- with torch.inference_mode():
96
- feature_emb = uni_model(uni_images.to(device))
97
- uni_emb.append(feature_emb)
98
-
99
- uni_emb = torch.stack(uni_emb, dim=0)
100
  print("Extracted UNI:", uni_emb.shape)
101
 
102
  # Get unconditional embedding for classifier-free guidance
103
  uncond = pipeline.get_unconditional_embedding(uni_emb.shape[0])
104
  # Generate new samples
105
- samples = pipeline(uni_embeds=uni_emb, negative_uni_embeds=uncond, guidance_scale=1.5, num_images_per_prompt=1)
 
106
  ```
 
68
 
69
  # This is an example image we provide
70
  path = hf_hub_download(repo_id="StonyBrook-CVLab/PixCell-1024", filename="test_image.png")
71
+ image = Image.open(path).convert("RGB")
72
+
73
+
74
+ # Rearrange 1024x1024 image into 16 256x256 patches
75
+ uni_patches = np.array(image)
76
+ uni_patches = einops.rearrange(uni_patches, '(d1 h) (d2 w) c -> (d1 d2) h w c', d1=4, d2=4)
77
+ uni_input = torch.stack([transform(Image.fromarray(item)) for item in uni_patches])
78
+
79
+ # Extract UNI embeddings
80
+ with torch.inference_mode():
81
+ uni_emb = uni_model(uni_input.to(device))
82
+
83
+ # reshape UNI to (bs, 16, D)
84
+ uni_emb = uni_emb.unsqueeze(0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  print("Extracted UNI:", uni_emb.shape)
86
 
87
  # Get unconditional embedding for classifier-free guidance
88
  uncond = pipeline.get_unconditional_embedding(uni_emb.shape[0])
89
  # Generate new samples
90
+ samples = pipeline(uni_embeds=uni_emb, negative_uni_embeds=uncond, guidance_scale=1.5).images
91
+
92
  ```