Spaces:
Running
on
Zero
Running
on
Zero
File size: 4,264 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
{
"cells": [
{
"cell_type": "markdown",
"id": "a885cf5d-c525-4f5b-a8e4-f67d2f699909",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"## Copyright 2023 Google LLC"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d891d022-8979-40d4-848f-ecb84c17f12c",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"pycharm": {
"name": "#%%\n"
}
},
"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": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"# StyleAligned over SD1.4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23d54ea7-f7ab-4548-9b10-ece87216dc18",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"from diffusers import DDIMScheduler,StableDiffusionPipeline\n",
"import torch\n",
"import mediapy\n",
"import sa_handler\n",
"import math"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "522b14e7-9768-4eaa-8433-bf88acb244c4",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"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 = StableDiffusionPipeline.from_pretrained(\n",
" \"CompVis/stable-diffusion-v1-4\",\n",
" revision=\"fp16\",\n",
" scheduler=scheduler\n",
")\n",
"pipeline = pipeline.to(\"cuda\")\n",
"\n",
"handler = sa_handler.Handler(pipeline)\n",
"sa_args = sa_handler.StyleAlignedArgs(share_group_norm=True,\n",
" share_layer_norm=True,\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": "5db98c81-8b72-4fc7-8cd0-65eda17198e3",
"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, generator=None).images\n",
"mediapy.show_images(images)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "afbe3876-22d9-4735-89b9-d5b5c46aea5c",
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"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
} |