File size: 11,417 Bytes
0576375 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
#!/bin/bash
set -e # Exit on any error
echo "============================================================================"
echo "VINE Model - Complete Setup Script"
echo "This script sets up everything needed to use the VINE model from HuggingFace"
echo "Model: https://huggingface.co/video-fm/vine"
echo "============================================================================"
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# ============================================================================
# Step 1: Create Conda Environment
# ============================================================================
echo ""
echo "=========================================="
echo "Step 1: Creating conda environment 'vine_demo' with Python 3.10..."
echo "=========================================="
conda create -n vine_demo python=3.10 -y
# Activate environment
echo ""
echo "Activating environment..."
source $(conda info --base)/etc/profile.d/conda.sh
conda activate vine_demo
# ============================================================================
# Step 2: Install PyTorch
# ============================================================================
echo ""
echo "=========================================="
echo "Step 2: Installing PyTorch 2.7.1 with CUDA 12.6 support..."
echo "=========================================="
pip install torch==2.7.1 torchvision==0.22.1 --index-url https://download.pytorch.org/whl/cu126
# Upgrade pip
pip install --upgrade pip
# ============================================================================
# Step 3: Install Core Dependencies
# ============================================================================
echo ""
echo "=========================================="
echo "Step 3: Installing core dependencies..."
echo "=========================================="
# Install transformers and HuggingFace tools
pip install transformers>=4.40.0
pip install huggingface-hub
pip install safetensors
pip install accelerate
# Install video processing dependencies
pip install opencv-python
pip install pillow
pip install matplotlib
pip install seaborn
pip install pandas
pip install numpy
pip install tqdm
pip install scikit-learn
# Install Gradio for demos (optional)
pip install gradio
echo "β Core dependencies installed"
# ============================================================================
# Step 4: Clone Required Repositories
# ============================================================================
echo ""
echo "=========================================="
echo "Step 4: Cloning required repositories..."
echo "=========================================="
mkdir -p src
cd src
# Clone SAM2
if [ ! -d "video-sam2" ]; then
echo "Cloning video-sam2..."
git clone https://github.com/video-fm/video-sam2.git
else
echo "video-sam2 already exists, skipping clone"
fi
# Clone GroundingDINO
if [ ! -d "GroundingDINO" ]; then
echo "Cloning GroundingDINO..."
git clone https://github.com/video-fm/GroundingDINO.git
else
echo "GroundingDINO already exists, skipping clone"
fi
# Clone LASER
if [ ! -d "LASER" ]; then
echo "Cloning LASER..."
git clone https://github.com/kevinxuez/LASER.git
else
echo "LASER already exists, skipping clone"
fi
# Clone vine_hf
if [ ! -d "vine_hf" ]; then
echo "Cloning vine_hf..."
git clone https://github.com/kevinxuez/vine_hf.git
else
echo "vine_hf already exists, skipping clone"
fi
echo "β Repositories cloned"
# ============================================================================
# Step 5: Install Packages in Editable Mode
# ============================================================================
echo ""
echo "=========================================="
echo "Step 5: Installing packages in editable mode..."
echo "=========================================="
echo "Installing video-sam2..."
pip install --no-cache-dir -e ./video-sam2
echo "Installing GroundingDINO..."
pip install --no-cache-dir --use-pep517 -e ./GroundingDINO
echo "Installing LASER..."
pip install --no-cache-dir -e ./LASER
echo "Installing vine_hf..."
pip install --no-cache-dir -e ./vine_hf
echo "β Packages installed"
# ============================================================================
# Step 6: Build GroundingDINO Extensions
# ============================================================================
echo ""
echo "=========================================="
echo "Step 6: Building GroundingDINO native extensions..."
echo "=========================================="
cd GroundingDINO
python setup.py build_ext --force --inplace
cd ..
# Return to main directory
cd "$SCRIPT_DIR"
echo "β Extensions built"
# ============================================================================
# Step 7: Download Model Checkpoints
# ============================================================================
echo ""
echo "=========================================="
echo "Step 7: Downloading model checkpoints..."
echo "=========================================="
# Create checkpoints directory
mkdir -p checkpoints
cd checkpoints
# Download SAM2 checkpoint (~149 MB)
if [ ! -f "sam2_hiera_tiny.pt" ]; then
echo "Downloading SAM2 checkpoint (sam2_hiera_tiny.pt ~149 MB)..."
wget -q --show-progress https://dl.fbaipublicfiles.com/segment_anything_2/072824/sam2_hiera_tiny.pt
echo "β SAM2 checkpoint downloaded"
else
echo "β SAM2 checkpoint already exists"
fi
# Download SAM2 config
if [ ! -f "sam2_hiera_t.yaml" ]; then
echo "Downloading SAM2 config (sam2_hiera_t.yaml)..."
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/sam2/main/sam2/configs/sam2.1/sam2.1_hiera_t.yaml -O sam2_hiera_t.yaml
echo "β SAM2 config downloaded"
else
echo "β SAM2 config already exists"
fi
# Download GroundingDINO checkpoint (~662 MB)
if [ ! -f "groundingdino_swint_ogc.pth" ]; then
echo "Downloading GroundingDINO checkpoint (groundingdino_swint_ogc.pth ~662 MB)..."
wget -q --show-progress https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
echo "β GroundingDINO checkpoint downloaded"
else
echo "β GroundingDINO checkpoint already exists"
fi
# Download GroundingDINO config
if [ ! -f "GroundingDINO_SwinT_OGC.py" ]; then
echo "Downloading GroundingDINO config (GroundingDINO_SwinT_OGC.py)..."
wget -q --show-progress https://raw.githubusercontent.com/IDEA-Research/GroundingDINO/main/groundingdino/config/GroundingDINO_SwinT_OGC.py
echo "β GroundingDINO config downloaded"
else
echo "β GroundingDINO config already exists"
fi
# Return to main directory
cd "$SCRIPT_DIR"
echo ""
echo "β All checkpoints downloaded to: $SCRIPT_DIR/checkpoints/"
# ============================================================================
# Step 8: Create Test Script
# ============================================================================
echo ""
echo "=========================================="
echo "Step 8: Creating test script..."
echo "=========================================="
cat > test_vine.py << 'TESTEOF'
"""
Test script for VINE model loaded from HuggingFace Hub
"""
import os
import sys
from pathlib import Path
os.environ['OPENAI_API_KEY'] = "dummy-key"
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
print("=" * 80)
print("Testing VINE Model from video-fm/vine")
print("=" * 80)
# Load VINE from HuggingFace
print("\n1. Loading VINE model from HuggingFace Hub...")
from transformers import AutoModel
model = AutoModel.from_pretrained('video-fm/vine', trust_remote_code=True)
print("β Model loaded successfully")
# Verify checkpoint files
print("\n2. Verifying checkpoint files...")
checkpoint_dir = Path(__file__).parent / "checkpoints"
checkpoints = {
"SAM2 config": checkpoint_dir / "sam2_hiera_t.yaml",
"SAM2 checkpoint": checkpoint_dir / "sam2_hiera_tiny.pt",
"GroundingDINO config": checkpoint_dir / "GroundingDINO_SwinT_OGC.py",
"GroundingDINO checkpoint": checkpoint_dir / "groundingdino_swint_ogc.pth",
}
all_exist = True
for name, path in checkpoints.items():
if path.exists():
size_mb = path.stat().st_size / (1024 * 1024)
print(f"β {name}: {path.name} ({size_mb:.1f} MB)")
else:
print(f"β {name}: NOT FOUND at {path}")
all_exist = False
# Create pipeline
print("\n3. Creating VINE pipeline...")
from vine_hf import VinePipeline
pipeline = VinePipeline(
model=model,
tokenizer=None,
sam_config_path=str(checkpoints["SAM2 config"]),
sam_checkpoint_path=str(checkpoints["SAM2 checkpoint"]),
gd_config_path=str(checkpoints["GroundingDINO config"]),
gd_checkpoint_path=str(checkpoints["GroundingDINO checkpoint"]),
device="cuda",
trust_remote_code=True
)
print("β Pipeline created successfully")
print("\n" + "=" * 80)
print("β
VINE Setup Complete and Working!")
print("=" * 80)
print("\nYou can now use the model for video understanding:")
print("""
from transformers import AutoModel
from vine_hf import VinePipeline
model = AutoModel.from_pretrained('video-fm/vine', trust_remote_code=True)
pipeline = VinePipeline(model=model, ...)
results = pipeline('video.mp4', categorical_keywords=['person', 'dog'], ...)
""")
TESTEOF
echo "β Test script created: test_vine.py"
# ============================================================================
# Step 9: Test the Installation
# ============================================================================
echo ""
echo "=========================================="
echo "Step 9: Testing installation..."
echo "=========================================="
echo "Checking PyTorch and CUDA..."
python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'CUDA available: {torch.cuda.is_available()}'); print(f'CUDA version: {torch.version.cuda if torch.cuda.is_available() else \"N/A\"}')"
echo ""
echo "Running VINE model test..."
python test_vine.py
# ============================================================================
# Final Summary
# ============================================================================
echo ""
echo "============================================================================"
echo "β
VINE Setup Complete!"
echo "============================================================================"
echo ""
echo "What was installed:"
echo " β Conda environment: vine_demo"
echo " β PyTorch 2.7.1 with CUDA 12.6"
echo " β Required packages: laser, sam2, groundingdino, vine_hf"
echo " β Model checkpoints downloaded to: checkpoints/"
echo ""
echo "Checkpoint files:"
echo " β checkpoints/sam2_hiera_tiny.pt (~149 MB)"
echo " β checkpoints/sam2_hiera_t.yaml"
echo " β checkpoints/groundingdino_swint_ogc.pth (~662 MB)"
echo " β checkpoints/GroundingDINO_SwinT_OGC.py"
echo ""
echo "To use VINE:"
echo " 1. Activate environment: conda activate vine_demo"
echo " 2. Run your script or test_vine.py"
echo ""
echo "Example usage:"
echo " python test_vine.py"
echo ""
echo "Model URL: https://huggingface.co/video-fm/vine"
echo "Documentation: See README.md on HuggingFace Hub"
echo ""
echo "π Happy video understanding with VINE!"
echo "============================================================================"
|