Skip to content

Commit

Permalink
refactored parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rlsn committed Mar 22, 2024
1 parent 7df33c1 commit eb9c982
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A pipeline that generate consecutive sequence of images with SD1.5. It's quite a
# 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.
- `generate_animation`: set false to generate a batch of images to choose from as an initial image, then set true to switch to animation mode.
- `nframes`: total number of frames to generate
- `scheduler`: choose one from "euler", "euler a", "DDIM", "DDPM", "DPM++ 2M SDE Karras", "DPM++ 2M Karras"
- `num_inference_steps`: per image
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"model_path": "your_model.safetensors",
"scheduler": "DPM++ 2M SDE Karras",
"generate_video": false,
"init_image" : "preview/your_init_image.jpg",
"prompt": "masterpiece, best quality, realistic, detailed background, the forgotten city made of white marble, grand, epic, fantasy, mystical, sunbeam, soft lighting, volumetric lighting, dramatic",
"generate_animation": false,
"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,
Expand Down
8 changes: 4 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import diffusers
import argparse
from attrdict import AttrDict
from utils import const_schedule, zoom, export_as_gif, timestr, interpolate_video
from utils import const_schedule, zoom, export_as_gif, timestr, interpolate_animation
import PIL

if __name__=="__main__":
Expand All @@ -22,14 +22,14 @@

tripper = Tripper(config.model_path)
tripper.set_scheduler(schedulers[config.scheduler])
if config.generate_video:
if config.generate_animation:
config.init_image = PIL.Image.open(config.init_image)
# strength schedule
config.strength_schedule = const_schedule(config.strength,config.nframes)
config.transform_fn = lambda img,s: zoom(img, config.zoom)
config.nsteps=int(config.nframes//config.diffusion_cadence)
imgs = tripper.generate_video(**config)
imgs = interpolate_video(imgs, config.diffusion_cadence)
imgs = tripper.generate_animation(**config)
imgs = interpolate_animation(imgs, config.diffusion_cadence)
export_as_gif(f"{config.out_dir}/{timestr()}.gif", imgs, frames_per_second=config.fps)
else:
tripper.txt2img(**config)
2 changes: 1 addition & 1 deletion tripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def img2img(self, image, prompt, negative_prompt, lora_dict, strength=0.5,
self.unload_lora(lora_dict)
return images

def generate_video(self, init_image, prompt, negative_prompt,
def generate_animation(self, init_image, prompt, negative_prompt,
lora_dict, nsteps, strength_schedule,
transform_fn,
guidance_scale=7,
Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def interpolation(img1, img2, num_frame=1):
imgs.append(Image.fromarray(im.astype(np.uint8)))
return imgs

def interpolate_video(imgs, cadence=2):
def interpolate_animation(imgs, cadence=2):
if cadence<=1:
return imgs
else:
Expand Down

0 comments on commit eb9c982

Please sign in to comment.