| model based on https://civitai.com/models/108124/realisticmechv1 | |
| converted to use it with animatediff with diffusers on hugging face | |
| A code sample : | |
| import torch | |
| from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter | |
| from diffusers.utils import export_to_gif | |
| # Load the motion adapter | |
| adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16) | |
| # Load SD 1.5 based finetuned model | |
| model_id = "zecloud/mechas" | |
| pipe = AnimateDiffPipeline.from_pretrained( | |
| model_id, | |
| motion_adapter=adapter, | |
| torch_dtype=torch.float16 | |
| ) | |
| scheduler = DDIMScheduler.from_pretrained( | |
| model_id, | |
| subfolder="scheduler", | |
| clip_sample=False, | |
| timestep_spacing="linspace", | |
| beta_schedule="linear", | |
| steps_offset=1, | |
| ) | |
| pipe.scheduler = scheduler | |
| # Enable memory savings | |
| pipe.enable_vae_slicing() | |
| pipe.enable_model_cpu_offload() | |
| # Define the input prompts and generate the output | |
| output = pipe( | |
| prompt=( | |
| "half body portrait of man smiling with a mysterious gaze, mecha, science_fiction, city, realistic,mecha, " | |
| "a futuristic eiffel tower in the background " | |
| ), | |
| negative_prompt=( | |
| "(worst quality, low quality:1.4), (bad_prompt_version2:0.8), EasyNegative, badhandv4, text, name, letters, " | |
| "watermark, two tower" | |
| ), | |
| num_frames=16, | |
| guidance_scale=7.0, | |
| num_inference_steps=32, | |
| generator=torch.Generator("cpu").manual_seed(42), | |
| ) | |
| # Extract frames and export to GIF | |
| frames = output.frames[0] | |
| export_to_gif(frames, "animation.gif") | |