-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
135 additions
and
51 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Tripper | ||
A wrapper that generate consecutive sequence of images with SD1.5. It's quite a trip to watch images evolving. Future work may enable SDXL. Inspired by [deforum](https://deforum.art/), check it out. | ||
 | ||
 | ||
# features | ||
- support loading lora models (safetensors) | ||
- support prompt token size exceeding 75, plus negative prompt | ||
- frame zoom in/out | ||
# Usage | ||
Edit the `config.json` to configure the settings: | ||
- `model_path`: path to your SD model safetensors | ||
- `generate_video`: set false to generate a batch of images to choose from as an initial image, then set true to switch to video mode. | ||
- `nsteps`: total number of images to generate | ||
- `scheduler`: choose one from "euler", "euler a", "DDIM", "DDPM", "DPM++ 2M SDE Karras", "DPM++ 2M Karras" | ||
- `num_inference_steps`: per image | ||
- `lora_dict`: dictionary containing: {"[path_to_lora_safetensor]":[weight]} | ||
- `zoom`: zoom in(<1) or out(>1), 0.98~1.02 is a sensible value (no zooming with 1) | ||
- `strength`: roughly the similarity between two consecutive images (0~1) | ||
then run with | ||
``` | ||
python run.py | ||
``` | ||
|
||
Have fun |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
An attribute dictionary that's very handy everywhere | ||
""" | ||
import json | ||
class AttrDict(dict): | ||
def __init__(self, *args, **kwargs): | ||
super(AttrDict, self).__init__(*args, **kwargs) | ||
self.__dict__ = self | ||
|
||
def to_json(self, filename): | ||
with open(filename, "w") as wf: | ||
wf.write(json.dumps(self, indent=4)) | ||
|
||
@classmethod | ||
def from_json(cls, filename): | ||
with open(filename, "r") as f: | ||
obj = cls(json.loads(f.read())) | ||
return obj |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"model_path": "your_model.safetensors", | ||
"scheduler": "DPM++ 2M SDE Karras", | ||
"generate_video": false, | ||
"init_image" : "preview/your_init_image.jpg", | ||
"prompt": "masterpiece, best quality, ultra-detailed, illustration, 1girl, solo, outdoors, camping, night, mountains, nature, stars, moon, tent, twin ponytails, green eyes, cheerful, happy, backpack, sleeping bag, camping stove, water bottle, mountain boots, gloves, sweater, hat, flashlight, forest, rocks, river, wood, smoke, shadows, contrast, clear sky, constellations, Milky Way, peaceful, serene, quiet, tranquil, remote, secluded, adventurous, exploration, escape, independence, survival, resourcefulness, challenge, perseverance, stamina, endurance, observation, intuition, adaptability, creativity, imagination, artistry, inspiration, beauty, awe, wonder, gratitude, appreciation, relaxation, enjoyment, rejuvenation, mindfulness, awareness, connection, harmony, balance, texture, detail, realism, depth, perspective, composition, color, light, shadow, reflection, refraction, tone, contrast, foreground, middle ground, background, naturalistic, figurative, representational, impressionistic, expressionistic, abstract, innovative, experimental, unique", | ||
"negative_prompt": "(worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), bad anatomy,ng_deepnegative_v1_75t,easynegative, badhandv4, text, watermark,", | ||
"strength":0.65, | ||
"num_img":6, | ||
"guidance_scale":6.5, | ||
"num_inference_steps":40, | ||
"nsteps":80, | ||
"width":768, | ||
"height":512, | ||
"zoom":0.98, | ||
"out_dir":"preview", | ||
"fps":10, | ||
"lora_dict":{ | ||
"your_lora_1.safetensors":0.5, | ||
"your_lora_2.safetensors":0.8 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Created on Mon Jul 25 2023 | ||
# | ||
# Copyright (c) 2023 rlsn | ||
# | ||
# !pip install diffusers transformers safetensors einops scipy | ||
|
||
from tripper import Tripper, schedulers | ||
import diffusers | ||
import argparse | ||
from attrdict import AttrDict | ||
from utils import const_schedule, zoom, export_as_gif, timestr | ||
import PIL | ||
|
||
if __name__=="__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--config_file', type=str, help="filename of the running configuration", default="config.json") | ||
|
||
args = parser.parse_args() | ||
config = AttrDict.from_json(args.config_file) | ||
print(f"running with config:{config}") | ||
|
||
tripper = Tripper(config.model_path) | ||
tripper.set_scheduler(schedulers[config.scheduler]) | ||
if config.generate_video: | ||
config.init_image = PIL.Image.open(config.init_image) | ||
|
||
# strength schedule | ||
config.strength_schedule = const_schedule(config.strength,config.nsteps) | ||
config.transform_fn = lambda img,s: zoom(img, config.zoom) | ||
imgs = tripper.generate_video(**config) | ||
export_as_gif(f"{config.out_dir}/{timestr()}.gif", imgs, frames_per_second=config.fps) | ||
else: | ||
tripper.txt2img(**config) |
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
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