install sam2 the way facebook says

This commit is contained in:
2025-07-26 08:14:35 -07:00
parent 8f9f021f96
commit 032ea9da4b
8 changed files with 102 additions and 90 deletions

View File

@@ -29,36 +29,22 @@ mkdir -p models
# Download YOLOv8 models
python -c "from ultralytics import YOLO; YOLO('yolov8n.pt'); YOLO('yolov8m.pt')"
# Download SAM2 checkpoints
cd models
echo "📥 Downloading SAM2 models..."
# Try different SAM2 model versions
if [ ! -f "sam2_hiera_large.pt" ]; then
echo "Trying SAM2 checkpoint version 1..."
wget -q --show-progress https://dl.fbaipublicfiles.com/segment_anything_2/sam2_hiera_large.pt || true
# Clone SAM2 repo for checkpoints
echo "📥 Cloning SAM2 for model checkpoints..."
if [ ! -d "segment-anything-2" ]; then
git clone https://github.com/facebookresearch/segment-anything-2.git
fi
# Download SAM2 checkpoints using their official script
cd segment-anything-2
mkdir -p checkpoints
cd checkpoints
if [ ! -f "sam2.1_hiera_large.pt" ]; then
echo "Trying SAM2.1 checkpoint (latest)..."
wget -q --show-progress https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt || true
echo "📥 Downloading SAM2 checkpoints..."
chmod +x ../download_ckpts.sh 2>/dev/null || true
bash ../download_ckpts.sh || bash <(curl -s https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/download_ckpts.sh)
fi
# Download SAM2 config files
cd ..
mkdir -p sam2_configs
cd sam2_configs
echo "📥 Downloading SAM2 configuration files..."
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2_hiera_b+.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2_hiera_l.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2_hiera_s.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2_hiera_t.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2.1_hiera_b+.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2.1_hiera_l.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2.1_hiera_s.yaml
wget -q --show-progress https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2.1_hiera_t.yaml
cd ..
cd ../..
# Create working directories
mkdir -p /workspace/data /workspace/output
@@ -68,16 +54,21 @@ echo ""
echo "🧪 Testing installation..."
python test_installation.py
# Check which SAM2 model is available
# Check which SAM2 models are available
echo ""
echo "📊 SAM2 Models available:"
if [ -f "models/sam2_hiera_large.pt" ]; then
echo " ✅ sam2_hiera_large.pt"
echo " Use in config: sam2_checkpoint: 'models/sam2_hiera_large.pt'"
fi
if [ -f "models/sam2.1_hiera_large.pt" ]; then
if [ -f "segment-anything-2/checkpoints/sam2.1_hiera_large.pt" ]; then
echo " ✅ sam2.1_hiera_large.pt (recommended)"
echo " Use in config: sam2_checkpoint: 'models/sam2.1_hiera_large.pt'"
echo " Config: sam2_model_cfg: 'sam2.1_hiera_l'"
echo " Checkpoint: sam2_checkpoint: 'segment-anything-2/checkpoints/sam2.1_hiera_large.pt'"
fi
if [ -f "segment-anything-2/checkpoints/sam2.1_hiera_base_plus.pt" ]; then
echo " ✅ sam2.1_hiera_base_plus.pt"
echo " Config: sam2_model_cfg: 'sam2.1_hiera_base_plus'"
fi
if [ -f "segment-anything-2/checkpoints/sam2_hiera_large.pt" ]; then
echo " ✅ sam2_hiera_large.pt (legacy)"
echo " Config: sam2_model_cfg: 'sam2_hiera_l'"
fi
echo ""