Spaces:
Sleeping
Sleeping
VREyeSAM - Model Security & Protection Guide
π Overview
VREyeSAM is protected with multiple security layers to prevent model weight extraction and ensure safe deployment.
Security Measures Implemented
1. Model Weight Protection
- β Model weights are loaded at startup and never exposed to the client
- β
Weights are managed in
model_server.pyusing a singleton pattern - β Checkpoint paths are resolved internally and never sent to the frontend
2. File System Isolation
- β Checkpoint files have restricted permissions (600)
- β Only the inference API is exposed to users
- β Raw file access is blocked
3. API-Only Architecture
- β No direct model file downloads
- β Only prediction results are returned to users
- β Model internals stay hidden
Deployment to Hugging Face Spaces
Prerequisites
- HuggingFace account with Spaces access
- Model weights in private HuggingFace repository
- Docker setup for containerized deployment
Step 1: Create Private Model Repository
# Clone your model repo (if not already done)
# Ensure checkpoints are NOT committed to git
# Add to .gitignore if needed
Step 2: Deploy to HF Spaces
- Go to Hugging Face Spaces
- Click "Create new Space"
- Fill in details:
- Space name: vreyesam
- License: MIT
- SDK: Docker
- Visibility: Public (only code, not weights)
- After creation, upload your
Dockerfileand code files
Step 3: Authentication for Model Downloads
For accessing private model weights during Docker build:
- Create HuggingFace token: https://huggingface.co/settings/tokens
- Set in Spaces environment (Settings β Secrets with HF_TOKEN)
- OR use direct URL with token (not recommended, keep private)
Step 4: Verify Security
Before deployment:
# Check what files will be uploaded
git status
git ls-files | grep -E '\.(pt|pth|torch|bin)$'
# Should output: (nothing - no weights!)
Security Checklist
- Model weights are in
.gitignore - Checkpoint paths are not hardcoded in code
- Only
model_server.pyhandles weight loading - Docker build uses secure downloads
-
.envfiles are in.gitignore - Frontend cannot access file paths
- API only exposes prediction results
Best Practices
β DO:
- Keep model weights private and download during deployment
- Use environment variables for configuration
- Only expose prediction API endpoints
- Log errors without exposing paths
- Use Hugging Face tokens securely in Spaces secrets
β DON'T:
- Commit model weights to git
- Hardcode checkpoint paths in code
- Expose debug routes that show model structure
- Log full file paths to users
- Include weights in Docker layers visible to users
Troubleshooting
Issue: "Model weights not found"
- Verify
.gitignorecontains checkpoint paths - Check Dockerfile correctly downloads from HuggingFace
- Ensure HF_TOKEN is set in Spaces secrets
Issue: "File path exposed in error"
- Update
model_server.pyto not show paths - Generic error messages only: "Model initialization failed"
- Check logs don't contain sensitive details
Advanced Security
Optional: Encrypt Weights
# In model_server.py
from cryptography.fernet import Fernet
encrypted_weights = Fernet(key).encrypt(state_dict)
Optional: Disable Direct File Access
# Set file permissions
chmod 600 segment-anything-2/checkpoints/*
# Only the app process can read them
Support
For security questions or issues:
- Check the GitHub Issues
- Contact: geetanjalisharma546@gmail.com
Last Updated: March 2025 Security Level: High Protection β