{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "2dff8591-ce0f-49eb-a0a3-be24464bf06e", "metadata": {}, "outputs": [], "source": [ "!pip install transformers ftfy torch accelerate\n", "!pip install --force-reinstall git+https://github.com/huggingface/diffusers.git\n", "!wget \"https://github.com/Cyberes/xformers-compiled/releases/download/A4000-Oct-28-2022/a4000-xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl\" -O xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl\n", "!pip install --force-reinstall xformers-0.0.14.dev0-cp39-cp39-linux_x86_64.whl" ] }, { "cell_type": "code", "execution_count": null, "id": "b1282338-bee8-485d-8d05-0185d4d367c8", "metadata": {}, "outputs": [], "source": [ "source_img = '/notebooks/test.png'\n", "prompt = 'an image'" ] }, { "cell_type": "code", "execution_count": null, "id": "2a447d3d-e1d6-413c-89ac-d29bb74b0ab2", "metadata": {}, "outputs": [], "source": [ "pipeline = StableDiffusionUpscalePipeline.from_pretrained(\"stabilityai/stable-diffusion-x4-upscaler\", revision=\"fp16\", torch_dtype=torch.float16)\n", "pipeline.to(\"cuda\")\n", "pipeline.enable_attention_slicing()\n", "pipeline.enable_xformers_memory_efficient_attention()" ] }, { "cell_type": "code", "execution_count": null, "id": "a4e125e1-dad0-48b3-b535-117a47858ab7", "metadata": {}, "outputs": [], "source": [ "low_res_img = Image.open(source_img).convert(\"RGB\")\n", "low_res_img = low_res_img.resize((128, 128)) # Have to do this or OOM since there's a few bugs that need to be fixed\n", "upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]\n", "upscaled_image.save(\"upsampled.png\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 5 }