# PowerShell script to check if all dependencies are installed # Run this script from the project root directory Write-Host "=========================================" -ForegroundColor Cyan Write-Host "Dependency Checker for SAM2 Image Auto Segment" -ForegroundColor Cyan Write-Host "=========================================" -ForegroundColor Cyan Write-Host "" # Check if Python is installed try { $pythonVersion = python --version 2>&1 Write-Host $pythonVersion -ForegroundColor Green } catch { Write-Host "[ERROR] Python is not installed or not in PATH!" -ForegroundColor Red Write-Host "Please install Python 3.10 or higher" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "Checking installed packages..." -ForegroundColor Yellow Write-Host "" $missingPackages = @() $packageChecks = @( @{Name="fastapi"; Import="fastapi"; Version="fastapi.__version__"}, @{Name="uvicorn"; Import="uvicorn"; Version="uvicorn.__version__"}, @{Name="numpy"; Import="numpy"; Version="numpy.__version__"}, @{Name="opencv-python"; Import="cv2"; Version="cv2.__version__"}, @{Name="Pillow"; Import="PIL"; Version="PIL.__version__"}, @{Name="scikit-image"; Import="skimage"; Version="skimage.__version__"}, @{Name="torch"; Import="torch"; Version="torch.__version__"}, @{Name="torchvision"; Import="torchvision"; Version="torchvision.__version__"}, @{Name="huggingface_hub"; Import="huggingface_hub"; Version="huggingface_hub.__version__"}, @{Name="omegaconf"; Import="omegaconf"; Version="omegaconf.__version__"}, @{Name="hydra-core"; Import="hydra"; Version="hydra.__version__"}, @{Name="iopath"; Import="iopath"; Version=""}, @{Name="tqdm"; Import="tqdm"; Version="tqdm.__version__"}, @{Name="requests"; Import="requests"; Version="requests.__version__"}, @{Name="psutil"; Import="psutil"; Version="psutil.__version__"} ) $index = 1 foreach ($pkg in $packageChecks) { $versionCmd = if ($pkg.Version) { "; print(' OK - $($pkg.Name)', $($pkg.Version))" } else { "; print(' OK - $($pkg.Name)')" } $checkCmd = "import $($pkg.Import)$versionCmd" Write-Host "[$index/15] Checking $($pkg.Name)..." -NoNewline $result = python -c $checkCmd 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host " $result" -ForegroundColor Green } else { Write-Host " [MISSING]" -ForegroundColor Red $missingPackages += $pkg.Name } $index++ } Write-Host "" Write-Host "Checking SAM2 package..." -NoNewline $sam2Check = python -c "import sam2; print(' OK - sam2 package is installed')" 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host " $sam2Check" -ForegroundColor Green } else { Write-Host " [NOT INSTALLED]" -ForegroundColor Yellow Write-Host " Run: cd sam2; python -m pip install -e .; cd .." -ForegroundColor Yellow $missingPackages += "sam2" } Write-Host "" Write-Host "=========================================" -ForegroundColor Cyan if ($missingPackages.Count -eq 0) { Write-Host "All dependencies are installed! ✓" -ForegroundColor Green Write-Host "" Write-Host "Testing critical imports..." -ForegroundColor Yellow $importChecks = @( @{Name="model.sam_model"; Import="from model.sam_model import predict_polygon"}, @{Name="model.utils"; Import="from model.utils import load_image_from_url"}, @{Name="sam2.automatic_mask_generator"; Import="from sam2.automatic_mask_generator import SAM2AutomaticMaskGenerator"} ) foreach ($imp in $importChecks) { $result = python -c $imp.Import 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host " OK - $($imp.Name)" -ForegroundColor Green } else { Write-Host " [WARNING] Cannot import $($imp.Name)" -ForegroundColor Yellow } } Write-Host "" Write-Host "✓ Ready to run the application!" -ForegroundColor Green } else { Write-Host "Missing packages: $($missingPackages -join ', ')" -ForegroundColor Red Write-Host "" Write-Host "Please install missing packages by running:" -ForegroundColor Yellow Write-Host " .\install_requirements.ps1" -ForegroundColor White Write-Host "" Write-Host "Or manually:" -ForegroundColor Yellow Write-Host " python -m pip install -r requirements.txt" -ForegroundColor White Write-Host " cd sam2" -ForegroundColor White Write-Host " python -m pip install -e ." -ForegroundColor White Write-Host " cd .." -ForegroundColor White } Write-Host "=========================================" -ForegroundColor Cyan Write-Host ""