readme: # Stable diffusion utils
  Currently has 2 modules: Tag explorer & CFG Scheduler.
  
  ## Usage
  **This script needs you to put `--disable-safe-unpickle` argument when starting your webui. Use at your own risk.**  
  (I don't know how to pass the safety check and it always throws `global 'torch/DoubleStorage' is forbidden` when I try to load the GPT model with `safe-unpickle`.)
  
  - Put `magicprompt_trunc20k_corpus_safe_underscore_160k-final.pt` under root of sd web-ui.  
  - Put `tag-explorer.py` to `scripts/`.  
  - Choose `Betairylia's utils` under `Script` section of your webui.  
  
  ## Tag explorer
  A [MagicPrompt](https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion) (GPT-2) model finetuned on Danbooru2021 corpus (comma connected tags, shuffled, tags with underscores; so tags are provided as `long_hair` etc.) with `rating:s` and `score > 10`.  
  Corpus preview:
  ```
  cowboy_shot, blunt_bangs, black_shorts, kurokami_(kurokaminohito), dog_tags, cleavage, bangs, black_hair, bracelet, eyebrows_visible_through_hair, head_tilt, thighhighs, short_shorts, collarbone, bare_shoulders, very_long_hair, original, shorts, swimsuit, o-ring_top, brown_eyes, kurono_mika, black_bikini, commentary_request, medium_breasts, floating_hair, sideboob, highleg_bikini, o-ring_bikini, groin, highres, hair_between_eyes, bikini, black_legwear, long_hair, bikini_under_clothes, thigh_strap, choker, open_mouth, jewelry, uneven_legwear, looking_at_viewer, asymmetrical_legwear, highleg, indoors, navel, solo, breasts, 1girl, standing, o-ring
  ```
  **By default it runs on the same device as your sd model. It will take 3~4 GiB vRAM.**  
  You can change `device` in `tag-explorer.py` to desired one, e.g., `cpu` or `cuda:1` etc.
  
  ## CFG Scheduler
  Currently supports Cosine / Polynomial scheduling during **DDIM** sampling.  
  **Other samplers won't work**.
  
  Inv means the scheduler will change the CFG scale to `max` at the beginning and `min` at the end.  
  `steepness` controls the curve of polynomial scheduler; higher = more drastic change near the end and vice versa:
  
  $$\text{CFG}(t) = \text{CFG}_\text{min} + (\text{CFG}_\text{max} - \text{CFG}_\text{min}) \cdot t^{\text{exp}(\text{steepness})}$$
  