From 0c55e1add6a4f984accab87c32571221e45a614e Mon Sep 17 00:00:00 2001 From: Bilal143260 Date: Thu, 7 Dec 2023 08:19:34 +0000 Subject: [PATCH 1/2] inference code --- .gitignore | 3 ++- inference.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 inference.py diff --git a/.gitignore b/.gitignore index bef7c1c5..130189ef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ pretrained_models ./*.png ./*.mp4 demo/tmp -demo/outputs \ No newline at end of file +demo/outputs +.venv \ No newline at end of file diff --git a/inference.py b/inference.py new file mode 100644 index 00000000..89308048 --- /dev/null +++ b/inference.py @@ -0,0 +1,37 @@ +import numpy as np +from PIL import Image +import imageio + +from demo.animate import MagicAnimate + +def read_video(video_path): + reader = imageio.get_reader(video_path) + # You might want to process the video frames here + return video_path + +def read_image(image_path, size=512): + image = Image.open(image_path) + return np.array(image.resize((size, size))) + +def main(reference_image, motion_sequence, seed, steps, guidance_scale): + animator = MagicAnimate() + + animation = animator(reference_image, motion_sequence, seed, steps, guidance_scale) + + # Assuming the output is in a format that can be saved with imageio + # imageio.mimsave('output_animation.mp4', animation) + return animation + +# Set your values here +reference_image_path = "/home/bilal/magic-animate/inputs/applications/source_image/multi1_source.png" +motion_sequence_path = "/home/bilal/magic-animate/inputs/applications/driving/densepose/multi_dancing.mp4" +seed = 1 +steps = 25 +guidance_scale = 7.5 + +# Read the image and video +reference_image = read_image(reference_image_path) +motion_sequence = read_video(motion_sequence_path) + +# Run the main function +main(reference_image, motion_sequence, seed, steps, guidance_scale) \ No newline at end of file From c46c515f2148d5dd49ee90cfa42d887de897f34c Mon Sep 17 00:00:00 2001 From: Bilal143260 Date: Thu, 7 Dec 2023 08:44:16 +0000 Subject: [PATCH 2/2] easy inference code --- inference.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/inference.py b/inference.py index 89308048..ac05df54 100644 --- a/inference.py +++ b/inference.py @@ -1,3 +1,4 @@ +import argparse import numpy as np from PIL import Image import imageio @@ -6,32 +7,29 @@ def read_video(video_path): reader = imageio.get_reader(video_path) - # You might want to process the video frames here return video_path def read_image(image_path, size=512): image = Image.open(image_path) return np.array(image.resize((size, size))) -def main(reference_image, motion_sequence, seed, steps, guidance_scale): +def main(reference_image_path, motion_sequence_path, seed, steps, guidance_scale): animator = MagicAnimate() - animation = animator(reference_image, motion_sequence, seed, steps, guidance_scale) + reference_image = read_image(reference_image_path) + motion_sequence = read_video(motion_sequence_path) - # Assuming the output is in a format that can be saved with imageio - # imageio.mimsave('output_animation.mp4', animation) + animation = animator(reference_image, motion_sequence, seed, steps, guidance_scale) return animation -# Set your values here -reference_image_path = "/home/bilal/magic-animate/inputs/applications/source_image/multi1_source.png" -motion_sequence_path = "/home/bilal/magic-animate/inputs/applications/driving/densepose/multi_dancing.mp4" -seed = 1 -steps = 25 -guidance_scale = 7.5 +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Animate images using MagicAnimate.") + parser.add_argument("reference_image", help="Path to the reference image") + parser.add_argument("motion_sequence", help="Path to the motion sequence video") + parser.add_argument("--seed", type=int, default=1, help="Random seed (default: 1)") + parser.add_argument("--steps", type=int, default=25, help="Sampling steps (default: 25)") + parser.add_argument("--guidance_scale", type=float, default=7.5, help="Guidance scale (default: 7.5)") -# Read the image and video -reference_image = read_image(reference_image_path) -motion_sequence = read_video(motion_sequence_path) + args = parser.parse_args() -# Run the main function -main(reference_image, motion_sequence, seed, steps, guidance_scale) \ No newline at end of file + main(args.reference_image, args.motion_sequence, args.seed, args.steps, args.guidance_scale)