Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing images in inference/controlnet.ipynb #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/astronaut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cat_dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sunflower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/three_people.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 9 additions & 11 deletions inference/controlnet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@
],
"source": [
"batch_size = 4\n",
"url = \"https://cdn.discordapp.com/attachments/1121232062708457508/1204787053892603914/cat_dog.png?ex=65d60061&is=65c38b61&hm=37c3d179a39b1eca4b8894e3c239930cedcbb965da00ae2209cca45f883f86f4&\"\n",
"images = resize_image(download_image(url)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"filename = \"assets/cat_dog.png\"\n",
"images = resize_image(load_image(filename)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"\n",
"batch = {'images': images}\n",
"\n",
Expand Down Expand Up @@ -370,8 +370,8 @@
],
"source": [
"batch_size = 4\n",
"url = \"https://cdn.discordapp.com/attachments/1039261364935462942/1200109692978999317/three_people.png?ex=65c4fc3f&is=65b2873f&hm=064a8cebea5560b74e7088be9d1399a5fe48863d1581e65ea9d6734725f4c8d3&\"\n",
"images = resize_image(download_image(url)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"filename = \"assets/three_people.png\"\n",
"images = resize_image(load_image(filename)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"\n",
"batch = {'images': images}\n",
"\n",
Expand Down Expand Up @@ -430,8 +430,8 @@
],
"source": [
"batch_size = 4\n",
"url = \"https://media.discordapp.net/attachments/1177378292765036716/1205484279405219861/image.png?ex=65d889b9&is=65c614b9&hm=0722ab9707b48d677316c0b4de5e51702b43eac1e27b76c268a069ec67ff6d15&=&format=webp&quality=lossless&width=861&height=859\"\n",
"images = resize_image(download_image(url)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"filename = \"assets/astronaut.png\"\n",
"images = resize_image(load_image(filename)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"sketch = False\n",
"\n",
"batch = {'images': images}\n",
Expand Down Expand Up @@ -489,10 +489,8 @@
"source": [
"batch_size = 4\n",
"cnet_override = None\n",
"# url = \"https://media.discordapp.net/attachments/1121232062708457508/1205134173053132810/image.png?ex=65d743a9&is=65c4cea9&hm=48dc4901514caada29271f48d76431f3a648940f2fda9e643a6bb693c906cc09&=&format=webp&quality=lossless&width=862&height=857\"\n",
"# url = \"https://cdn.discordapp.com/attachments/1121232062708457508/1204787053892603914/cat_dog.png?ex=65d60061&is=65c38b61&hm=37c3d179a39b1eca4b8894e3c239930cedcbb965da00ae2209cca45f883f86f4&\"\n",
"url = \"https://cdn.discordapp.com/attachments/1121232062708457508/1205110687538479145/A_photograph_of_a_sunflower_with_sunglasses_on_in__3.jpg?ex=65d72dc9&is=65c4b8c9&hm=72172e774ce6cda618503b3778b844de05cd1208b61e185d8418db512fb2858a&\"\n",
"images = resize_image(download_image(url)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"filename = \"assets/sunflower.png\"\n",
"images = resize_image(load_image(filename)).unsqueeze(0).expand(batch_size, -1, -1, -1)\n",
"\n",
"batch = {'images': images}\n",
"\n",
Expand Down Expand Up @@ -662,7 +660,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
14 changes: 9 additions & 5 deletions inference/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import torchvision.transforms.functional as F


def load_image(fp):
return PIL.Image.open(fp).convert("RGB")


def download_image(url):
return PIL.Image.open(requests.get(url, stream=True).raw).convert("RGB")
return load_image(requests.get(url, stream=True).raw)


def resize_image(image, size=768):
Expand All @@ -30,7 +34,7 @@ def show_images(images, rows=None, cols=None, return_images=False, **kwargs):
images = images.repeat(1, 3, 1, 1)
elif images.size(1) > 3:
images = images[:, :3]

if rows is None:
rows = 1
if cols is None:
Expand All @@ -42,7 +46,7 @@ def show_images(images, rows=None, cols=None, return_images=False, **kwargs):
for i, img in enumerate(images):
img = torchvision.transforms.functional.to_pil_image(img.clamp(0, 1))
grid.paste(img, box=(i % cols * w, i // cols * h))

bio = BytesIO()
grid.save(bio, format='png')
display(Image(bio.getvalue(), format='png'))
Expand All @@ -56,9 +60,9 @@ def calculate_latent_sizes(height=1024, width=1024, batch_size=4, compression_fa
latent_height = ceil(height / compression_factor_b)
latent_width = ceil(width / compression_factor_b)
stage_c_latent_shape = (batch_size, 16, latent_height, latent_width)

latent_height = ceil(height / compression_factor_a)
latent_width = ceil(width / compression_factor_a)
stage_b_latent_shape = (batch_size, 4, latent_height, latent_width)

return stage_c_latent_shape, stage_b_latent_shape