fix shit code
This commit is contained in:
parent
7414a1848c
commit
1ca5096639
|
@ -3,17 +3,14 @@
|
|||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2a447d3d-e1d6-413c-89ac-d29bb74b0ab2",
|
||||
"id": "2dff8591-ce0f-49eb-a0a3-be24464bf06e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# !pip install --force-reinstall git+https://github.com/huggingface/diffusers.git\n",
|
||||
"\n",
|
||||
"# load model and scheduler\n",
|
||||
"from diffusers import StableDiffusionUpscalePipeline, DPMSolverMultistepScheduler\n",
|
||||
"import torch\n",
|
||||
"pipeline = StableDiffusionUpscalePipeline.from_pretrained(\"stabilityai/stable-diffusion-x4-upscaler\", revision=\"fp16\", torch_dtype=torch.float16)\n",
|
||||
"pipeline.to(\"cuda\")"
|
||||
"!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"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -27,6 +24,19 @@
|
|||
"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,
|
||||
|
@ -34,48 +44,11 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from PIL import Image\n",
|
||||
"\n",
|
||||
"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\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3199cd6a-108a-422f-a4cc-f384f9f55bb1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"from PIL import Image\n",
|
||||
"from io import BytesIO\n",
|
||||
"from diffusers import StableDiffusionUpscalePipeline\n",
|
||||
"import torch\n",
|
||||
"\n",
|
||||
"# load model and scheduler\n",
|
||||
"model_id = \"stabilityai/stable-diffusion-x4-upscaler\"\n",
|
||||
"pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, revision=\"fp16\", torch_dtype=torch.float16)\n",
|
||||
"pipeline = pipeline.to(\"cuda\")\n",
|
||||
"\n",
|
||||
"# let's download an image\n",
|
||||
"url = \"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png\"\n",
|
||||
"response = requests.get(url)\n",
|
||||
"low_res_img = Image.open(BytesIO(response.content)).convert(\"RGB\")\n",
|
||||
"low_res_img = low_res_img.resize((128, 128))\n",
|
||||
"prompt = \"a white cat\"\n",
|
||||
"upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]\n",
|
||||
"upscaled_image.save(\"upsampled_cat.png\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4cd5c9ea-367a-48ab-aed1-73854ca42848",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
Loading…
Reference in New Issue