CoolFace
Apppublic

ysharma/style-aligned-controlnet

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