Initial snapshot: hand motion pipeline (Dyn-HaMR + dex-retargeting + SPIDER)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Convert MP4 videos to optimized GIFs for GitHub README display.
|
||||
This script creates smaller, optimized GIFs suitable for web display.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import imageio
|
||||
from pathlib import Path
|
||||
|
||||
def convert_mp4_to_gif(mp4_path, gif_path, max_frames=150, fps=10, scale=0.5):
|
||||
"""
|
||||
Convert MP4 to optimized GIF.
|
||||
|
||||
Args:
|
||||
mp4_path: Path to input MP4 file
|
||||
gif_path: Path to output GIF file
|
||||
max_frames: Maximum number of frames to include (for file size)
|
||||
fps: Frames per second for output GIF
|
||||
scale: Scale factor (0.5 = half size)
|
||||
"""
|
||||
print(f"Converting {mp4_path} to {gif_path}...")
|
||||
|
||||
try:
|
||||
# Read video
|
||||
reader = imageio.get_reader(mp4_path)
|
||||
fps_original = reader.get_meta_data()['fps']
|
||||
|
||||
# Calculate frame skip to get desired fps
|
||||
frame_skip = max(1, int(fps_original / fps))
|
||||
|
||||
frames = []
|
||||
frame_count = 0
|
||||
|
||||
for i, frame in enumerate(reader):
|
||||
if i % frame_skip == 0 and frame_count < max_frames:
|
||||
# Resize frame
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
img = Image.fromarray(frame)
|
||||
new_size = (int(img.width * scale), int(img.height * scale))
|
||||
img_resized = img.resize(new_size, Image.Resampling.LANCZOS)
|
||||
frames.append(np.array(img_resized))
|
||||
frame_count += 1
|
||||
|
||||
reader.close()
|
||||
|
||||
# Write GIF
|
||||
imageio.mimsave(gif_path, frames, fps=fps, loop=0)
|
||||
print(f" ✓ Created {gif_path} ({frame_count} frames, {fps} fps)")
|
||||
|
||||
# Get file sizes
|
||||
mp4_size = os.path.getsize(mp4_path) / (1024 * 1024) # MB
|
||||
gif_size = os.path.getsize(gif_path) / (1024 * 1024) # MB
|
||||
print(f" Size: {mp4_size:.1f} MB → {gif_size:.1f} MB")
|
||||
|
||||
except Exception as e:
|
||||
print(f" ✗ Error: {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def main():
|
||||
assets_dir = Path(__file__).parent.parent / "assets"
|
||||
|
||||
videos = [
|
||||
"droid_result.mp4",
|
||||
"vipe_result.mp4",
|
||||
"handedness1.mp4",
|
||||
"handedness2.mp4",
|
||||
"handedness3.mp4",
|
||||
"handedness4.mp4",
|
||||
]
|
||||
|
||||
print("Converting videos to GIFs for GitHub README...")
|
||||
print("=" * 60)
|
||||
|
||||
for video in videos:
|
||||
mp4_path = assets_dir / video
|
||||
gif_path = assets_dir / video.replace(".mp4", ".gif")
|
||||
|
||||
if not mp4_path.exists():
|
||||
print(f"⚠ Skipping {video} (not found)")
|
||||
continue
|
||||
|
||||
convert_mp4_to_gif(mp4_path, gif_path, max_frames=1000, fps=20, scale=0.6)
|
||||
print()
|
||||
|
||||
print("=" * 60)
|
||||
print("Done! Update README.md to use .gif files instead of .mp4")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
export CONDA_ENV_NAME=dynhamr
|
||||
|
||||
conda create -n $CONDA_ENV_NAME python=3.10 -y
|
||||
|
||||
conda activate $CONDA_ENV_NAME
|
||||
|
||||
# install pytorch using pip, update with appropriate cuda drivers if necessary
|
||||
pip install torch==1.13.0 torchvision==0.14.0 --index-url https://download.pytorch.org/whl/cu117
|
||||
# uncomment if pip installation isn't working
|
||||
# conda install pytorch=1.13.0 torchvision=0.14.0 pytorch-cuda=11.7 -c pytorch -c nvidia -y
|
||||
|
||||
# install pytorch scatter using pip, update with appropriate cuda drivers if necessary
|
||||
pip install torch-scatter -f https://data.pyg.org/whl/torch-1.13.0+cu117.html
|
||||
# uncomment if pip installation isn't working
|
||||
# conda install pytorch-scatter -c pyg -y
|
||||
|
||||
# install remaining requirements
|
||||
pip install -r requirements.txt
|
||||
|
||||
# install source
|
||||
pip install -e .
|
||||
|
||||
# install DROID-SLAM/DPVO
|
||||
cd third-party/DROID-SLAM
|
||||
python setup.py install
|
||||
cd ../..
|
||||
|
||||
# install HaMeR
|
||||
cd third-party/HaMeR
|
||||
pip install -e .[all]
|
||||
pip install -v -e third-party/ViTPose
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo "Creating virtual environment"
|
||||
python3.10 -m venv .dynhamr
|
||||
echo "Activating virtual environment"
|
||||
|
||||
source $PWD/.dynhamr/bin/activate
|
||||
|
||||
# install pytorch
|
||||
$PWD/.dynhamr/bin/pip install torch==1.13.0 torchvision==0.14.0 --index-url https://download.pytorch.org/whl/cu117
|
||||
|
||||
# torch-scatter
|
||||
$PWD/.dynhamr/bin/pip install torch-scatter -f https://data.pyg.org/whl/torch-1.13.0+cu117.html
|
||||
|
||||
# install source
|
||||
$PWD/.dynhamr/bin/pip install -e .
|
||||
|
||||
# install remaining requirements
|
||||
$PWD/.dynhamr/bin/pip install -r requirements.txt
|
||||
|
||||
# install DROID-SLAM/DPVO
|
||||
cd third-party/DROID-SLAM
|
||||
python setup.py install
|
||||
cd ../..
|
||||
|
||||
# install HaMeR
|
||||
cd third-party/HaMeR
|
||||
pip install -e .[all]
|
||||
pip install -v -e third-party/ViTPose
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
# Download for HaMeR
|
||||
gdown https://drive.google.com/uc?id=1mv7CUAnm73oKsEEG1xE3xH2C_oqcFSzT
|
||||
# Alternatively, you can use wget
|
||||
#wget https://www.cs.utexas.edu/~pavlakos/hamer/data/hamer_demo_data.tar.gz
|
||||
tar --warning=no-unknown-keyword --exclude=".*" -xvf hamer_demo_data.tar.gz
|
||||
rm -rf hamer_demo_data.tar.gz
|
||||
|
||||
# Download for SLAM
|
||||
gdown https://drive.google.com/uc?id=1VD1vGhl_NPzy8mza4Fx6vvqFpnlzZ86L
|
||||
mv droid.pth ./_DATA/
|
||||
|
||||
# Download for HMP
|
||||
gdown https://drive.google.com/uc?id=1_rp_SMxZA6Gjm6Z49M6hXam9kjMD6-GQ
|
||||
unzip hmp_model.zip
|
||||
mv hmp_model ./_DATA/
|
||||
rm -rf hmp_model.zip
|
||||
|
||||
wget https://huggingface.co/spaces/rolpotamias/WiLoR/resolve/main/pretrained_models/detector.pt -P ./third-party/hamer/pretrained_models/
|
||||
Reference in New Issue
Block a user