This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
from keras.applications.inception_v3 import InceptionV3 | |
from keras.optimizers import Adam | |
from keras.utils.io_utils import HDF5Matrix | |
class threadsafe_iter: | |
"""Takes an iterator/generator and makes it thread-safe by | |
serializing call to the `next` method of given iterator/generator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required by (\ SHELL COMMANDS \) | |
SHELL:=/bin/bash | |
VIRT_ENV_FOLDER = ~/.local/share/virtualenvs/xnli | |
SOURCE_VIRT_ENV = source $(VIRT_ENV_FOLDER)/bin/activate | |
.PHONY: train | |
train: | |
( \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ALEPH by Advadnoun, https://colab.research.google.com/drive/1Q-TbYvASMPRMXCOQjkxxf72CXYjR_8Vp | |
# "This is a notebook that uses DALL-E's decoder and CLIP to generate images from text. I will very likely make this better & easier to use in the future." | |
# | |
# rearranged to run locally on faster GPU | |
# | |
# directions: | |
# clone https://github.com/openai/DALL-E/ and https://github.com/openai/CLIP | |
# copy relevant files into one dir with this script | |
# install torch==1.7.1 and other stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!pip install diffusers==0.2.4 | |
import torch | |
from diffusers import AutoencoderKL | |
from PIL import Image | |
import numpy as np | |
from torchvision import transforms as tfms | |
torch_device = None | |
vae = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def prompt_combinations(prompt_parts): | |
''' | |
Provide a list of lists of prompt parts, like: | |
[ ["A ","An "], ["anteater","feather duster"] ] | |
''' | |
opt_prompt = list(itertools.product(*prompt_parts, repeat=1)) | |
opt_prompt = [''.join(opt_prompt[b]) for b in range(len(opt_prompt))] | |
return opt_prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clip-retrieval inference \ | |
--input_dataset="<parent folder containing images>" \ | |
--output_folder="<output s3 bucket or local folder>" \ | |
--input_format="files" \ | |
--enable_metadata=False \ | |
--write_batch_size=500 \ | |
--num_prepro_workers=2 \ | |
--batch_size=64 \ | |
--enable_wandb=True \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch import FloatTensor | |
vae_scale_factor = 8 | |
typical_self_attn_key_length = (512/vae_scale_factor) * (512/vae_scale_factor) | |
desired_self_attn_key_length = (200/vae_scale_factor) * (200/vae_scale_factor) | |
key_length_factor=desired_self_attn_key_length/typical_self_attn_key_length if is_self_attn else 1. | |
def softmax(x: FloatTensor, dim=-1) -> FloatTensor: | |
key_tokens = x.size(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import math | |
from numpy.typing import NDArray | |
# we are trying to make buckets of varying aspect ratios, | |
# all with about the same area (equivalent to a 512x512 square) | |
square_side = 512 | |
buckets = 8 | |
widest_aspect: float = math.atan2(1, 2) # 1/2 = 0.5 aspect ratio |
OlderNewer