ASethi04 commited on
Commit
0576375
Β·
verified Β·
1 Parent(s): cb58bbd

Add complete self-contained setup script with checkpoint downloads

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