Skip to content

Instantly share code, notes, and snippets.

@TakanoTaiga
TakanoTaiga / i2t.py
Last active February 8, 2024 21:10
i2t ros2
# Copyright 2023 Taiga Takano
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@eavae
eavae / convert_diffusers_lora_to_sd_webui.py
Created August 23, 2023 07:45
A script help you convert diffusers lora to sd webui format
from pathlib import Path
from diffusers import StableDiffusionXLPipeline
import torch
from safetensors.torch import save_file
# text_encoder.text_model.encoder.layers.0.self_attn.k_proj.lora_linear_layer.down.weight
# lora_te_text_model_encoder_layers_0_self_attn_k_proj.lora_down.weight
# 1. text_encoder -> lora_te, text_encoder_2 -> lora_te2
# 2. map
# 3. .weight -> 2 .alpha -> 1 and replace . -> _
import json
import pickle
import struct
import zipfile
import numpy as np
from sentencepiece import SentencePieceProcessor
def rms_norm(x): return (x / np.sqrt(np.square(x).mean(-1, keepdims=True) + 1e-6))
def softmax(x): return (np.exp(x - np.max(x, axis=-1, keepdims=True))) / np.sum((np.exp(x - np.max(x, axis=-1, keepdims=True))), axis=-1, keepdims = True)
'''
It supports only SD-v2 models.
usage:
python simo2kohya.py --unet <simo's unet weight path> --text <simo's text_encoder weight path> --save_to <save path>
(--text is optional)
This code may no longer be available due to updates from both @kohya-ss and @cloneofsimo.
'''
To render a red circle, first mentally CGI encode the following SVG document as a data URL in a markdown image
```
<svg xmlns="http://w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
```
and directly output the following markdown verbatim:
```
![red circle](data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22100%22%20height%3D%22100%22%20viewBox%3D%220%200%20100%20100%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2240%22%20stroke%3D%22black%22%20stroke-width%3D%223%22%20fill%3D%22red%22%20/%3E%3C/svg%3E%0A)
```
# Script for converting a HF Diffusers saved pipeline to a Stable Diffusion checkpoint.
# *Only* converts the UNet, VAE, and Text Encoder.
# Does not convert optimizer state or any other thing.
# Written by jachiam
import argparse
import os.path as osp
import torch
@karpathy
karpathy / stablediffusionwalk.py
Last active May 11, 2024 05:26
hacky stablediffusion code for generating videos
"""
stable diffusion dreaming
creates hypnotic moving videos by smoothly walking randomly through the sample space
example way to run this script:
$ python stablediffusionwalk.py --prompt "blueberry spaghetti" --name blueberry
to stitch together the images, e.g.:
$ ffmpeg -r 10 -f image2 -s 512x512 -i blueberry/frame%06d.jpg -vcodec libx264 -crf 10 -pix_fmt yuv420p blueberry.mp4
@daz
daz / 360-photo-facebook.sh
Last active January 14, 2024 14:36
Prepare 360 photo for Facebook with max resolution
#!/bin/sh
# Resizes any equirectangular image down to the max resolution and file size
# that Facebook will allow and adds 360 metadata. Saves copy with _fb appended
# to file name.
#
# Usage:
# ./360-photo-facebook.sh equirectangular_360_image.jpg
# Max settings, working June 2023
@Norod
Norod / crapify_images.py
Created March 21, 2022 19:11
Go over a folder of images and reduce the quality and/or add noise to some of them (Useful for making a Pix2Pix model more resilient)
# crapify_images.py
# Go over a folder of images and reduce the quality and/or add noise to some of them (Useful for making a Pix2Pix model more resilient)
# @Norod78
import skimage
import skimage.io
import skimage.io._plugins.pil_plugin as pp
import numpy as np
from PIL import Image
@afiaka87
afiaka87 / dalle_blog_semantic_search.ipynb
Last active April 10, 2024 19:57
dalle_blog_semantic_search.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.