update readme
Browse files
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 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
for
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 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
|
|
|
|
| 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 |
```
|