Skip to content

Instantly share code, notes, and snippets.

View afiaka87's full-sized avatar
🤪

Clay Mullis afiaka87

🤪
View GitHub Profile
@afiaka87
afiaka87 / finetune_clip_wds.py
Last active September 29, 2023 09:35
Finetune CLIP on a 'webdataset' formatted dataset
from torchvision.transforms.transforms import GaussianBlur
import webdataset as wds
import io
from PIL import Image
from clip.loader import TextImageDataset
from clip.clip import load, tokenize
from torchvision import transforms as T
from torch.utils.data import DataLoader
from torch.optim import Adam
import torch.nn.functional as F
@afiaka87
afiaka87 / filter_cah.py
Last active September 25, 2021 04:27
Clean and Filter Crawling @ Home by length, aspect ratio, image size, detected language
number_regex = re.compile(r'[0-9]{5,}')
date_regex = re.compile(r'[0-9]{4}-[0-9]{2}-[0-9]{2}')
url_regex = re.compile(r'https?://[^\s]+')
@lru_cache(maxsize=32)
def tokenize(s):
s = s.decode('utf-8')
s = s.lower()
s = number_regex.sub('', s)
@afiaka87
afiaka87 / finetune_glide.py
Created December 31, 2021 02:56
Finetune GLIDE (small filtered) from Open AI. WIP.
import argparse
import sys
sys.path.append("./glide-text2im")
import torch as th
from glide_text2im.download import load_checkpoint
from glide_text2im.model_creation import (create_model_and_diffusion,
model_and_diffusion_defaults)
from guided_diffusion import dist_util, logger
from guided_diffusion.image_text_datasets import load_data
from guided_diffusion.resample import create_named_schedule_sampler
@afiaka87
afiaka87 / openai_captions.txt
Created January 4, 2022 07:58
Captions for dalle from the openai cdn. Removed all mannequin captions.
This file has been truncated, but you can view the full file.
an illustration of a bunny in a beanie sipping a latte
a small red book sitting on a large green book
a black and white photograph of a fox sitting on a mountain during spring
a poster of a cougar sitting on a mountain during summer
an illustration of a baby penguin in a leather jacket using a calculator
a pencil sketch of a pangolin sitting on a mountain at dawn
a professional high quality illustration of a pig isopod chimera. a pig imitating an isopod. a pig made of isopod.
a rug with an image of a pink cucumber
an emoji of a baby fox wearing a red hat, green gloves, yellow shirt, and blue pants
a small blue block standing behind a large red block
@afiaka87
afiaka87 / detic_image_folder.py
Last active March 9, 2022 12:58
(WIP) Point at a folder of images, get box labels with probs in a folder
#%%
# cd Detic/
# %%
import detectron2
from detectron2.utils.logger import setup_logger
from pathlib import Path
from random import randint, choice
import time
import PIL
from PIL import Image
@afiaka87
afiaka87 / finetune_glide_v2.py
Created January 18, 2022 06:22
Finetune GLIDE on a captioned-images dataset e.g. COCO/LAION
# https://wandb.ai/afiaka87/glide_finetune/runs/3fj69lfc?workspace=user-afiaka87
from lzma import MODE_NORMAL
from PIL import Image
import os
import wandb
from IPython.display import display
import torch as th
from glide_text2im import xf
from glide_text2im.download import load_checkpoint
import pathlib
from csv import writer
import torch
import tqdm
from PIL import Image
from torch.utils.data import Dataset
from torchvision import transforms
from torchvision.transforms.functional import InterpolationMode
from data import create_loader
import discord
from datetime import datetime
import replicate
import asyncio
import logging
logging.basicConfig(level=logging.INFO)
import os
[
"t-shirt, size M",
"flower dress, size M",
"a t-shirt of an avocado",
"a rainbow hat",
"white snow covered mountain under blue sky during daytime",
"aerial view of the beach during daytime",
"aerial view of the beach at night",
"double rainbow over a lake",
"a beautiful sunset at a beach with a shell on the shore",
import os
from typing import List
import numpy as np
import torch
from cog import BasePredictor, Input, Path
from diffusers import (
AutoencoderKL,
LMSDiscreteScheduler,
UNet2DConditionModel,