diff --git a/example.py b/example.py deleted file mode 100644 index 1804eda..0000000 --- a/example.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Example script showing how to use MatAnyone programmatically. -""" -import os -import torch -from inference_matanyone import process_video - -# Enable CUDA if available -device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') -print(f"Using device: {device}") - -# Define paths -input_video = "inputs/video/my_video.mp4" # Replace with your video path -mask_image = "inputs/mask/my_mask.png" # Replace with your mask path -output_dir = "results" - -# Create output directory if it doesn't exist -os.makedirs(output_dir, exist_ok=True) - -# Process the video -fgr_path, pha_path = process_video( - input_path=input_video, - mask_path=mask_image, - output_path=output_dir, - n_warmup=10, # Number of warmup iterations - r_erode=10, # Erosion kernel size - r_dilate=10, # Dilation kernel size - max_size=1280, # Limit the maximum size (optional) - save_image=False # Whether to save individual frames -) - -print(f"Processing complete!") -print(f"Foreground video saved to: {fgr_path}") -print(f"Alpha matte saved to: {pha_path}") - -# Example of how to use the outputs -print("\nNext steps:") -print("1. Use the foreground video (fgr) with a green background for chroma keying") -print("2. Use the alpha matte (pha) as a transparency mask in video editing software") -print("3. Combine them to composite your subject onto a new background") \ No newline at end of file diff --git a/example_comfyui.py b/example_comfyui.py deleted file mode 100644 index d5ad3dd..0000000 --- a/example_comfyui.py +++ /dev/null @@ -1,77 +0,0 @@ -""" -Example workflow for using MatAnyone in ComfyUI - -This is a Python representation of a ComfyUI workflow. -You can use this as a reference for how to connect nodes. -""" - -import torch -import numpy as np -from PIL import Image -import os - -# This is a representation of how you would use the node in ComfyUI -# In the actual ComfyUI interface, you would connect nodes visually - -def example_workflow(): - # Step 1: Load video frames - # In ComfyUI, you would use a video loader node - # Here we're just creating dummy frames for illustration - video_frames = torch.rand(10, 3, 512, 512) # 10 frames, RGB, 512x512 - - # Step 2: Create a mask for the first frame - # In ComfyUI, you would use a mask drawing tool or load a mask - mask = torch.zeros(512, 512) - # Draw a circle in the center as an example foreground - center_x, center_y = 256, 256 - radius = 100 - for y in range(512): - for x in range(512): - if (x - center_x)**2 + (y - center_y)**2 < radius**2: - mask[y, x] = 1.0 - - # Step 3: Process with MatAnyone - # In ComfyUI, this would be the MatAnyone node - from __init__ import MatAnyoneNode - matanyone_node = MatAnyoneNode() - - # Make sure the model is downloaded - model_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "model") - os.makedirs(model_dir, exist_ok=True) - model_path = os.path.join(model_dir, "matanyone.pth") - - if not os.path.exists(model_path): - print(f"Please download the model from https://github.com/pq-yang/MatAnyone/releases/download/v1.0.0/matanyone.pth") - print(f"and place it in {model_dir}") - return - - # Process the video - foreground_frames, alpha_frames = matanyone_node.process_video( - video_frames=video_frames, - mask=mask, - warmup_frames=10, - erode_kernel=10, - dilate_kernel=10, - max_size=-1 - ) - - # Step 4: Use the results - # In ComfyUI, you would connect these to other nodes - print(f"Foreground frames shape: {foreground_frames.shape}") - print(f"Alpha frames shape: {alpha_frames.shape}") - - # Example: Save the first frame as an image - fg_frame = foreground_frames[0].permute(1, 2, 0).cpu().numpy() - fg_frame = (fg_frame * 255).astype(np.uint8) - fg_image = Image.fromarray(fg_frame) - fg_image.save("example_foreground.png") - - alpha_frame = alpha_frames[0][0].cpu().numpy() - alpha_frame = (alpha_frame * 255).astype(np.uint8) - alpha_image = Image.fromarray(alpha_frame) - alpha_image.save("example_alpha.png") - - print("Example images saved!") - -if __name__ == "__main__": - example_workflow() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e16dedf..0807101 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ -torch>=1.13.0 -torchvision>=0.14.0 numpy>=1.20.0 opencv-python>=4.5.0 Pillow>=9.0.0 omegaconf>=2.1.0 -huggingface_hub>=0.12.0 \ No newline at end of file +requests +tqdm \ No newline at end of file