Spaces:
Running
on
Zero
Running
on
Zero
File size: 4,045 Bytes
2d87298 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
{
"cells": [
{
"cell_type": "markdown",
"id": "a885cf5d-c525-4f5b-a8e4-f67d2f699909",
"metadata": {},
"source": [
"## Copyright 2023 Google LLC"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d891d022-8979-40d4-848f-ecb84c17f12c",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"outputs": [],
"source": [
"# Copyright 2023 Google LLC\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"#\n",
"# http://www.apache.org/licenses/LICENSE-2.0\n",
"#\n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
},
{
"cell_type": "markdown",
"id": "540d8642-c203-471c-a66d-0d43aabb0706",
"metadata": {},
"source": [
"# StyleAligned over SDXL"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23d54ea7-f7ab-4548-9b10-ece87216dc18",
"metadata": {},
"outputs": [],
"source": [
"from diffusers import StableDiffusionXLPipeline, DDIMScheduler\n",
"import torch\n",
"import mediapy\n",
"import sa_handler"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2f6f1e6-445f-47bc-b9db-0301caeb7490",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# init models\n",
"\n",
"scheduler = DDIMScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule=\"scaled_linear\", clip_sample=False,\n",
" set_alpha_to_one=False)\n",
"pipeline = StableDiffusionXLPipeline.from_pretrained(\n",
" \"stabilityai/stable-diffusion-xl-base-1.0\", torch_dtype=torch.float16, variant=\"fp16\", use_safetensors=True,\n",
" scheduler=scheduler\n",
").to(\"cuda\")\n",
"\n",
"handler = sa_handler.Handler(pipeline)\n",
"sa_args = sa_handler.StyleAlignedArgs(share_group_norm=False,\n",
" share_layer_norm=False,\n",
" share_attention=True,\n",
" adain_queries=True,\n",
" adain_keys=True,\n",
" adain_values=False,\n",
" )\n",
"\n",
"handler.register(sa_args, )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5cca9256-0ce0-45c3-9cba-68c7eff1452f",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# run StyleAligned\n",
"\n",
"sets_of_prompts = [\n",
" \"a toy train. macro photo. 3d game asset\",\n",
" \"a toy airplane. macro photo. 3d game asset\",\n",
" \"a toy bicycle. macro photo. 3d game asset\",\n",
" \"a toy car. macro photo. 3d game asset\",\n",
" \"a toy boat. macro photo. 3d game asset\",\n",
"]\n",
"images = pipeline(sets_of_prompts,).images\n",
"mediapy.show_images(images)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d819ad6d-0c19-411f-ba97-199909f64805",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
} |