Spaces:
Sleeping
Sleeping
Georg
Claude Sonnet 4.5
commited on
Commit
·
837e5f7
1
Parent(s):
bed6b38
Add weight download on startup and clean up documentation
Browse files- Add download_weights_if_needed() function to app.py
- Download weights from HF model repo at startup if USE_REAL_MODEL=true
- Remove all extra MD files (DEPLOYMENT, HF_MODEL_SETUP, etc.)
- Keep only README.md
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- DEPLOYMENT.md +0 -184
- HF_MODEL_SETUP.md +0 -163
- PRIVATE_REPO_SETUP.md +0 -211
- QUICKSTART.md +0 -270
- README_SETUP.md +0 -216
- STATUS.md +0 -383
- UPLOAD_WEIGHTS.md +0 -328
- app.py +44 -0
DEPLOYMENT.md
DELETED
|
@@ -1,184 +0,0 @@
|
|
| 1 |
-
# FoundationPose Hugging Face Space Deployment Guide
|
| 2 |
-
|
| 3 |
-
This directory contains the code for deploying FoundationPose on Hugging Face Spaces with ZeroGPU support.
|
| 4 |
-
|
| 5 |
-
## Current Status
|
| 6 |
-
|
| 7 |
-
- ✅ Gradio app structure created
|
| 8 |
-
- ✅ API endpoints defined (/initialize, /estimate)
|
| 9 |
-
- ✅ ZeroGPU decorators added (@spaces.GPU)
|
| 10 |
-
- ✅ Client library for API calls created
|
| 11 |
-
- ⚠️ FoundationPose model integration incomplete (placeholder code)
|
| 12 |
-
|
| 13 |
-
## Next Steps
|
| 14 |
-
|
| 15 |
-
### 1. Complete FoundationPose Integration
|
| 16 |
-
|
| 17 |
-
The current `app.py` has placeholder code marked with `# TODO` comments. You need to:
|
| 18 |
-
|
| 19 |
-
1. **Install FoundationPose in the Space**:
|
| 20 |
-
- Add FoundationPose installation to requirements.txt or use a custom Dockerfile
|
| 21 |
-
- Download pre-trained weights (need to be included in the Space or downloaded at startup)
|
| 22 |
-
|
| 23 |
-
2. **Implement model initialization** (line ~40 in app.py):
|
| 24 |
-
```python
|
| 25 |
-
# Replace the TODO with actual FoundationPose initialization
|
| 26 |
-
from FoundationPose import FoundationPoseEstimator
|
| 27 |
-
self.model = FoundationPoseEstimator(device=self.device)
|
| 28 |
-
```
|
| 29 |
-
|
| 30 |
-
3. **Implement object registration** (line ~70):
|
| 31 |
-
```python
|
| 32 |
-
# Replace the TODO with actual registration
|
| 33 |
-
self.model.register_object(object_id, reference_images, camera_intrinsics)
|
| 34 |
-
```
|
| 35 |
-
|
| 36 |
-
4. **Implement pose estimation** (line ~120):
|
| 37 |
-
```python
|
| 38 |
-
# Replace the TODO with actual inference
|
| 39 |
-
result = self.model.estimate_pose(object_id, query_image, camera_intrinsics)
|
| 40 |
-
```
|
| 41 |
-
|
| 42 |
-
### 2. Handle Model Weights
|
| 43 |
-
|
| 44 |
-
FoundationPose requires pre-trained weights. Options:
|
| 45 |
-
|
| 46 |
-
**Option A: Git LFS (Recommended)**
|
| 47 |
-
```bash
|
| 48 |
-
cd foundationpose
|
| 49 |
-
git lfs install
|
| 50 |
-
mkdir weights
|
| 51 |
-
# Download weights from FoundationPose repo
|
| 52 |
-
wget https://... -O weights/model.pth
|
| 53 |
-
git lfs track "weights/*.pth"
|
| 54 |
-
git add weights/model.pth .gitattributes
|
| 55 |
-
git commit -m "Add model weights"
|
| 56 |
-
```
|
| 57 |
-
|
| 58 |
-
**Option B: Download at Runtime**
|
| 59 |
-
Add to `app.py`:
|
| 60 |
-
```python
|
| 61 |
-
def download_weights():
|
| 62 |
-
from huggingface_hub import hf_hub_download
|
| 63 |
-
weights_path = hf_hub_download(
|
| 64 |
-
repo_id="NVlabs/FoundationPose",
|
| 65 |
-
filename="model.pth"
|
| 66 |
-
)
|
| 67 |
-
return weights_path
|
| 68 |
-
```
|
| 69 |
-
|
| 70 |
-
### 3. Test Locally
|
| 71 |
-
|
| 72 |
-
Before deploying, test the Space locally:
|
| 73 |
-
|
| 74 |
-
```bash
|
| 75 |
-
cd foundationpose
|
| 76 |
-
pip install -r requirements.txt
|
| 77 |
-
python app.py
|
| 78 |
-
```
|
| 79 |
-
|
| 80 |
-
This will start a local Gradio server at http://localhost:7860
|
| 81 |
-
|
| 82 |
-
### 4. Deploy to Hugging Face
|
| 83 |
-
|
| 84 |
-
```bash
|
| 85 |
-
cd foundationpose
|
| 86 |
-
git add .
|
| 87 |
-
git commit -m "Add FoundationPose inference implementation"
|
| 88 |
-
git push
|
| 89 |
-
```
|
| 90 |
-
|
| 91 |
-
The Space will automatically rebuild and deploy.
|
| 92 |
-
|
| 93 |
-
### 5. Monitor GPU Usage
|
| 94 |
-
|
| 95 |
-
After deployment:
|
| 96 |
-
1. Check the Space logs for GPU allocation messages
|
| 97 |
-
2. Monitor inference times (cold start vs warm)
|
| 98 |
-
3. Adjust `@spaces.GPU(duration=X)` parameters if needed
|
| 99 |
-
|
| 100 |
-
### 6. Integrate with Training Pipeline
|
| 101 |
-
|
| 102 |
-
Once the Space is working, update the training code:
|
| 103 |
-
|
| 104 |
-
**In training/nova_sim_trainer/perception/foundation_pose_wrapper.py**:
|
| 105 |
-
```python
|
| 106 |
-
from foundationpose.client import FoundationPoseClient
|
| 107 |
-
|
| 108 |
-
class FoundationPoseWrapper(PoseEstimator):
|
| 109 |
-
def __init__(self, api_url: str, ...):
|
| 110 |
-
self.client = FoundationPoseClient(api_url)
|
| 111 |
-
# Initialize with reference images
|
| 112 |
-
ref_images = load_reference_images(reference_dir)
|
| 113 |
-
self.client.initialize(object_id, ref_images)
|
| 114 |
-
|
| 115 |
-
def estimate_poses(self, frame, camera_intrinsics, scene_objects):
|
| 116 |
-
poses = self.client.estimate_pose(self.object_id, frame, camera_intrinsics)
|
| 117 |
-
return [DetectedPose(**pose) for pose in poses]
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
**In training/observations.yaml**:
|
| 121 |
-
```yaml
|
| 122 |
-
perception:
|
| 123 |
-
enabled: true
|
| 124 |
-
model: foundation_pose
|
| 125 |
-
api_url: https://gpue-foundationpose.hf.space
|
| 126 |
-
tracked_objects:
|
| 127 |
-
- object_id: target_cube
|
| 128 |
-
reference_images_dir: ./perception/reference/target_cube
|
| 129 |
-
```
|
| 130 |
-
|
| 131 |
-
## Performance Considerations
|
| 132 |
-
|
| 133 |
-
### ZeroGPU Latency
|
| 134 |
-
- **Cold start**: 15-30 seconds (GPU allocation + model loading)
|
| 135 |
-
- **Warm inference**: 0.5-2 seconds per query
|
| 136 |
-
- **GPU duration**: Tune the `duration` parameter in `@spaces.GPU` decorators
|
| 137 |
-
|
| 138 |
-
### Recommended Usage
|
| 139 |
-
- ✅ **Batch processing**: Process multiple frames in one GPU allocation
|
| 140 |
-
- ✅ **Validation**: Check perception quality on recorded episodes
|
| 141 |
-
- ✅ **Demos**: Show 6D pose estimation capabilities
|
| 142 |
-
- ⚠️ **Real-time training**: Too slow for 30 Hz control loop - use dummy estimator instead
|
| 143 |
-
|
| 144 |
-
### Optimization Tips
|
| 145 |
-
1. **Batch multiple queries** to amortize cold start time
|
| 146 |
-
2. **Keep GPU warm** by sending periodic keep-alive requests
|
| 147 |
-
3. **Use lower resolution** if inference is too slow
|
| 148 |
-
4. **Cache results** for static scenes
|
| 149 |
-
|
| 150 |
-
## Troubleshooting
|
| 151 |
-
|
| 152 |
-
### Space won't start
|
| 153 |
-
- Check Space logs for errors
|
| 154 |
-
- Verify all dependencies in requirements.txt
|
| 155 |
-
- Check Python version compatibility (3.12)
|
| 156 |
-
|
| 157 |
-
### GPU timeout
|
| 158 |
-
- Increase `duration` in `@spaces.GPU(duration=X)`
|
| 159 |
-
- Optimize model inference code
|
| 160 |
-
- Reduce image resolution
|
| 161 |
-
|
| 162 |
-
### Out of memory
|
| 163 |
-
- Reduce batch size
|
| 164 |
-
- Use smaller model variant
|
| 165 |
-
- Request more GPU memory in Space settings
|
| 166 |
-
|
| 167 |
-
## Alternative: Docker Deployment
|
| 168 |
-
|
| 169 |
-
If ZeroGPU is too restrictive, consider running locally with Docker:
|
| 170 |
-
|
| 171 |
-
```bash
|
| 172 |
-
cd foundationpose
|
| 173 |
-
docker build -t foundationpose .
|
| 174 |
-
docker run -p 7860:7860 --gpus all foundationpose
|
| 175 |
-
```
|
| 176 |
-
|
| 177 |
-
Then set `api_url: http://localhost:7860` in observations.yaml.
|
| 178 |
-
|
| 179 |
-
## References
|
| 180 |
-
|
| 181 |
-
- [FoundationPose GitHub](https://github.com/NVlabs/FoundationPose)
|
| 182 |
-
- [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces)
|
| 183 |
-
- [ZeroGPU Documentation](https://huggingface.co/docs/hub/spaces-gpus-zerogpu)
|
| 184 |
-
- [Gradio Documentation](https://www.gradio.app/docs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HF_MODEL_SETUP.md
DELETED
|
@@ -1,163 +0,0 @@
|
|
| 1 |
-
# Quick Guide: Setting Up Model Weights on Hugging Face
|
| 2 |
-
|
| 3 |
-
**TL;DR:** Host your FoundationPose weights in a HF model repository instead of your Space. It's easier, faster, and better.
|
| 4 |
-
|
| 5 |
-
## Why This Way is Better
|
| 6 |
-
|
| 7 |
-
| Method | Pros | Cons |
|
| 8 |
-
|--------|------|------|
|
| 9 |
-
| **HF Model Repo** ✅ | Fast CDN downloads, version control, share across Spaces, no git-lfs needed | Initial setup required |
|
| 10 |
-
| Git-LFS in Space | All-in-one repo | Slow, complex, Space bloat, hard to share |
|
| 11 |
-
| Manual upload to Space files | Simple | Not version controlled, no programmatic access |
|
| 12 |
-
|
| 13 |
-
## 5-Minute Setup
|
| 14 |
-
|
| 15 |
-
### 1. Download Weights (One-Time)
|
| 16 |
-
|
| 17 |
-
```bash
|
| 18 |
-
# Download from Google Drive:
|
| 19 |
-
# https://drive.google.com/drive/folders/1GCyGE-LbFGgRC-FuGsF3a1zeBuzsQ1Da
|
| 20 |
-
|
| 21 |
-
# You need:
|
| 22 |
-
# - 2023-10-28-18-33-37/ (~900MB)
|
| 23 |
-
# - 2024-01-11-20-02-45/ (~900MB)
|
| 24 |
-
```
|
| 25 |
-
|
| 26 |
-
### 2. Create Model Repo
|
| 27 |
-
|
| 28 |
-
```bash
|
| 29 |
-
pip install huggingface_hub
|
| 30 |
-
huggingface-cli login
|
| 31 |
-
huggingface-cli repo create foundationpose-weights --type model
|
| 32 |
-
```
|
| 33 |
-
|
| 34 |
-
Or create at: https://huggingface.co/new (select "Model")
|
| 35 |
-
|
| 36 |
-
### 3. Upload Weights
|
| 37 |
-
|
| 38 |
-
```bash
|
| 39 |
-
cd /path/to/your/downloaded/weights
|
| 40 |
-
|
| 41 |
-
huggingface-cli upload YOUR_USERNAME/foundationpose-weights \
|
| 42 |
-
./2023-10-28-18-33-37 \
|
| 43 |
-
2023-10-28-18-33-37
|
| 44 |
-
|
| 45 |
-
huggingface-cli upload YOUR_USERNAME/foundationpose-weights \
|
| 46 |
-
./2024-01-11-20-02-45 \
|
| 47 |
-
2024-01-11-20-02-45
|
| 48 |
-
```
|
| 49 |
-
|
| 50 |
-
### 4. Configure Your Space
|
| 51 |
-
|
| 52 |
-
Add to your Space's environment variables (Settings → Variables and secrets):
|
| 53 |
-
|
| 54 |
-
```
|
| 55 |
-
FOUNDATIONPOSE_MODEL_REPO=YOUR_USERNAME/foundationpose-weights
|
| 56 |
-
USE_HF_WEIGHTS=true
|
| 57 |
-
USE_REAL_MODEL=true
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
-
### 5. Deploy
|
| 61 |
-
|
| 62 |
-
```bash
|
| 63 |
-
cd foundationpose
|
| 64 |
-
git push origin main
|
| 65 |
-
```
|
| 66 |
-
|
| 67 |
-
Your Space will automatically download weights on first run!
|
| 68 |
-
|
| 69 |
-
## Verify It Works
|
| 70 |
-
|
| 71 |
-
Check your Space logs at:
|
| 72 |
-
`https://huggingface.co/spaces/YOUR_USERNAME/foundationpose/logs`
|
| 73 |
-
|
| 74 |
-
Look for:
|
| 75 |
-
```
|
| 76 |
-
Downloading from Hugging Face Model Repository
|
| 77 |
-
Repository: YOUR_USERNAME/foundationpose-weights
|
| 78 |
-
✓ Download complete!
|
| 79 |
-
```
|
| 80 |
-
|
| 81 |
-
## Example Model Repo Structure
|
| 82 |
-
|
| 83 |
-
Your model repo should look like:
|
| 84 |
-
|
| 85 |
-
```
|
| 86 |
-
YOUR_USERNAME/foundationpose-weights/
|
| 87 |
-
├── README.md
|
| 88 |
-
├── 2023-10-28-18-33-37/
|
| 89 |
-
│ ├── model_0000000.pth
|
| 90 |
-
│ ├── config.json
|
| 91 |
-
│ └── ...
|
| 92 |
-
└── 2024-01-11-20-02-45/
|
| 93 |
-
├── model_0000000.pth
|
| 94 |
-
├── config.json
|
| 95 |
-
└── ...
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
## Use in Other Projects
|
| 99 |
-
|
| 100 |
-
Anyone can now use your weights:
|
| 101 |
-
|
| 102 |
-
```python
|
| 103 |
-
from huggingface_hub import snapshot_download
|
| 104 |
-
|
| 105 |
-
# Download weights
|
| 106 |
-
snapshot_download(
|
| 107 |
-
repo_id="YOUR_USERNAME/foundationpose-weights",
|
| 108 |
-
local_dir="./weights"
|
| 109 |
-
)
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
## Make It Public or Private?
|
| 113 |
-
|
| 114 |
-
**Public (Recommended):**
|
| 115 |
-
- ✅ Anyone can use (including your Space)
|
| 116 |
-
- ✅ No token needed
|
| 117 |
-
- ✅ Community can benefit
|
| 118 |
-
|
| 119 |
-
**Private:**
|
| 120 |
-
- ✅ Control access
|
| 121 |
-
- ❌ Need HF token in Space secrets
|
| 122 |
-
- ❌ More complex setup
|
| 123 |
-
|
| 124 |
-
For private repos, add `HF_TOKEN` to Space secrets.
|
| 125 |
-
|
| 126 |
-
## Common Issues
|
| 127 |
-
|
| 128 |
-
**"Repository not found"**
|
| 129 |
-
→ Check name matches: `YOUR_USERNAME/foundationpose-weights`
|
| 130 |
-
|
| 131 |
-
**"Access denied"**
|
| 132 |
-
→ Make repo public or add HF_TOKEN secret
|
| 133 |
-
|
| 134 |
-
**"Download slow"**
|
| 135 |
-
→ First download is cached, subsequent runs are instant
|
| 136 |
-
|
| 137 |
-
**"Out of space"**
|
| 138 |
-
→ Free tier: ~50GB. Upgrade or use smaller models.
|
| 139 |
-
|
| 140 |
-
## Complete Example
|
| 141 |
-
|
| 142 |
-
```bash
|
| 143 |
-
# Assuming weights downloaded to ~/Downloads/foundationpose-weights/
|
| 144 |
-
|
| 145 |
-
# 1. Login
|
| 146 |
-
huggingface-cli login
|
| 147 |
-
|
| 148 |
-
# 2. Create repo
|
| 149 |
-
huggingface-cli repo create foundationpose-weights --type model
|
| 150 |
-
|
| 151 |
-
# 3. Upload
|
| 152 |
-
cd ~/Downloads/foundationpose-weights
|
| 153 |
-
huggingface-cli upload gpue/foundationpose-weights . .
|
| 154 |
-
|
| 155 |
-
# 4. Done! Configure your Space:
|
| 156 |
-
# FOUNDATIONPOSE_MODEL_REPO=gpue/foundationpose-weights
|
| 157 |
-
# USE_HF_WEIGHTS=true
|
| 158 |
-
# USE_REAL_MODEL=true
|
| 159 |
-
```
|
| 160 |
-
|
| 161 |
-
---
|
| 162 |
-
|
| 163 |
-
**Full details:** See [UPLOAD_WEIGHTS.md](UPLOAD_WEIGHTS.md) for comprehensive guide.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRIVATE_REPO_SETUP.md
DELETED
|
@@ -1,211 +0,0 @@
|
|
| 1 |
-
# Private Model Repository Setup
|
| 2 |
-
|
| 3 |
-
Your model repository `gpue/foundationpose-weights` is currently **PRIVATE** 🔒
|
| 4 |
-
|
| 5 |
-
This document explains your options for using it with your Space.
|
| 6 |
-
|
| 7 |
-
---
|
| 8 |
-
|
| 9 |
-
## Quick Answer
|
| 10 |
-
|
| 11 |
-
**Yes, your Space needs a token** if the model repo stays private.
|
| 12 |
-
|
| 13 |
-
**No token needed** if you make the repo public.
|
| 14 |
-
|
| 15 |
-
---
|
| 16 |
-
|
| 17 |
-
## Option 1: Make Repository Public (Easiest) ✅
|
| 18 |
-
|
| 19 |
-
### Why Choose This?
|
| 20 |
-
- ✅ No token management
|
| 21 |
-
- ✅ Simpler Space setup
|
| 22 |
-
- ✅ Anyone can use your weights
|
| 23 |
-
- ✅ No secrets to manage
|
| 24 |
-
- ✅ Faster downloads (no auth overhead)
|
| 25 |
-
|
| 26 |
-
### How to Make Public
|
| 27 |
-
|
| 28 |
-
**Via CLI:**
|
| 29 |
-
```bash
|
| 30 |
-
/Users/georgpuschel/repos/robot-ml/training/.venv/bin/huggingface-cli repo update \
|
| 31 |
-
gpue/foundationpose-weights \
|
| 32 |
-
--visibility public \
|
| 33 |
-
--repo-type model
|
| 34 |
-
```
|
| 35 |
-
|
| 36 |
-
**Via Web:**
|
| 37 |
-
1. Go to https://huggingface.co/gpue/foundationpose-weights/settings
|
| 38 |
-
2. Under "Change repository visibility"
|
| 39 |
-
3. Select "Public"
|
| 40 |
-
4. Click "Update repository"
|
| 41 |
-
|
| 42 |
-
**Then:**
|
| 43 |
-
- Just deploy your Space - no additional setup needed!
|
| 44 |
-
- Weights will download automatically
|
| 45 |
-
|
| 46 |
-
---
|
| 47 |
-
|
| 48 |
-
## Option 2: Keep Private + Add Token 🔒
|
| 49 |
-
|
| 50 |
-
### Why Choose This?
|
| 51 |
-
- 🔒 Control access to weights
|
| 52 |
-
- 🔒 Keep it between your Spaces
|
| 53 |
-
- 🔒 Track who downloads
|
| 54 |
-
|
| 55 |
-
### Setup Steps
|
| 56 |
-
|
| 57 |
-
#### 1. Create HF Token
|
| 58 |
-
|
| 59 |
-
Go to https://huggingface.co/settings/tokens and create a new token:
|
| 60 |
-
|
| 61 |
-
- **Name:** `foundationpose-space` (or any name you want)
|
| 62 |
-
- **Type:** `Read` (not Write)
|
| 63 |
-
- **Permissions:**
|
| 64 |
-
- ✅ Read access to repos
|
| 65 |
-
|
| 66 |
-
Copy the token (starts with `hf_...`)
|
| 67 |
-
|
| 68 |
-
#### 2. Add Token to Space
|
| 69 |
-
|
| 70 |
-
Go to your Space settings:
|
| 71 |
-
https://huggingface.co/spaces/gpue/foundationpose/settings
|
| 72 |
-
|
| 73 |
-
Scroll to **"Repository secrets"** and add:
|
| 74 |
-
|
| 75 |
-
| Name | Value |
|
| 76 |
-
|------|-------|
|
| 77 |
-
| `HF_TOKEN` | `hf_xxxxxxxxxxxxx` (your token) |
|
| 78 |
-
|
| 79 |
-
#### 3. Verify
|
| 80 |
-
|
| 81 |
-
The code already supports token authentication:
|
| 82 |
-
- `download_weights.py` will automatically use `HF_TOKEN` if available
|
| 83 |
-
- No code changes needed!
|
| 84 |
-
|
| 85 |
-
#### 4. Test
|
| 86 |
-
|
| 87 |
-
Deploy your Space and check the logs:
|
| 88 |
-
```
|
| 89 |
-
🔒 Using HF_TOKEN for authentication (private repository)
|
| 90 |
-
Downloading model weights...
|
| 91 |
-
✓ Download complete!
|
| 92 |
-
```
|
| 93 |
-
|
| 94 |
-
---
|
| 95 |
-
|
| 96 |
-
## Current Status
|
| 97 |
-
|
| 98 |
-
✅ **Model repo uploaded:** 258MB (2 weight files + configs + README)
|
| 99 |
-
✅ **Token support added:** Code updated to use `HF_TOKEN` env var
|
| 100 |
-
✅ **Dockerfile configured:** Points to your model repo by default
|
| 101 |
-
❌ **Repository visibility:** Currently PRIVATE
|
| 102 |
-
|
| 103 |
-
---
|
| 104 |
-
|
| 105 |
-
## Recommendation
|
| 106 |
-
|
| 107 |
-
For a public inference Space like this, I recommend **making the model repo public**:
|
| 108 |
-
|
| 109 |
-
**Pros:**
|
| 110 |
-
- Simpler setup
|
| 111 |
-
- No token management
|
| 112 |
-
- Aligns with open-source spirit
|
| 113 |
-
- Easier for others to use
|
| 114 |
-
|
| 115 |
-
**Cons:**
|
| 116 |
-
- Anyone can download the weights (but they're from official FoundationPose anyway)
|
| 117 |
-
|
| 118 |
-
The FoundationPose weights are already public on Google Drive, so there's no confidentiality concern.
|
| 119 |
-
|
| 120 |
-
---
|
| 121 |
-
|
| 122 |
-
## Testing
|
| 123 |
-
|
| 124 |
-
### Verify Current Access
|
| 125 |
-
|
| 126 |
-
```bash
|
| 127 |
-
cd /Users/georgpuschel/repos/robot-ml/foundationpose
|
| 128 |
-
|
| 129 |
-
# Test without token (will fail if private)
|
| 130 |
-
unset HF_TOKEN
|
| 131 |
-
/Users/georgpuschel/repos/robot-ml/training/.venv/bin/python verify_weights.py
|
| 132 |
-
|
| 133 |
-
# Test with token (will work if token valid)
|
| 134 |
-
export HF_TOKEN="hf_your_token_here"
|
| 135 |
-
/Users/georgpuschel/repos/robot-ml/training/.venv/bin/python verify_weights.py
|
| 136 |
-
```
|
| 137 |
-
|
| 138 |
-
### After Making Public
|
| 139 |
-
|
| 140 |
-
```bash
|
| 141 |
-
# Should work without token
|
| 142 |
-
/Users/georgpuschel/repos/robot-ml/training/.venv/bin/python verify_weights.py
|
| 143 |
-
```
|
| 144 |
-
|
| 145 |
-
---
|
| 146 |
-
|
| 147 |
-
## What I've Done
|
| 148 |
-
|
| 149 |
-
1. ✅ Uploaded weights to `gpue/foundationpose-weights` (258MB)
|
| 150 |
-
2. ✅ Added README.md to model repo with citation and usage
|
| 151 |
-
3. ✅ Updated `download_weights.py` to support `HF_TOKEN`
|
| 152 |
-
4. ✅ Updated Dockerfile to point to your model repo
|
| 153 |
-
5. ✅ Created `verify_weights.py` to test access
|
| 154 |
-
6. ✅ Improved error messages for auth failures
|
| 155 |
-
|
| 156 |
-
---
|
| 157 |
-
|
| 158 |
-
## Next Steps (Choose One)
|
| 159 |
-
|
| 160 |
-
### If Making Public:
|
| 161 |
-
```bash
|
| 162 |
-
# 1. Make repo public
|
| 163 |
-
huggingface-cli repo update gpue/foundationpose-weights --visibility public --repo-type model
|
| 164 |
-
|
| 165 |
-
# 2. Deploy Space
|
| 166 |
-
cd /Users/georgpuschel/repos/robot-ml/foundationpose
|
| 167 |
-
git add .
|
| 168 |
-
git commit -m "Configure for model repo download"
|
| 169 |
-
git push origin main
|
| 170 |
-
|
| 171 |
-
# 3. Done! No token needed.
|
| 172 |
-
```
|
| 173 |
-
|
| 174 |
-
### If Keeping Private:
|
| 175 |
-
```bash
|
| 176 |
-
# 1. Get token from: https://huggingface.co/settings/tokens
|
| 177 |
-
|
| 178 |
-
# 2. Add HF_TOKEN to Space secrets:
|
| 179 |
-
# https://huggingface.co/spaces/gpue/foundationpose/settings
|
| 180 |
-
|
| 181 |
-
# 3. Deploy Space
|
| 182 |
-
cd /Users/georgpuschel/repos/robot-ml/foundationpose
|
| 183 |
-
git add .
|
| 184 |
-
git commit -m "Configure for model repo download"
|
| 185 |
-
git push origin main
|
| 186 |
-
|
| 187 |
-
# 4. Space will authenticate with token automatically
|
| 188 |
-
```
|
| 189 |
-
|
| 190 |
-
---
|
| 191 |
-
|
| 192 |
-
## FAQ
|
| 193 |
-
|
| 194 |
-
**Q: What if I forget to add the token?**
|
| 195 |
-
A: Space will run in placeholder mode (empty results but API works).
|
| 196 |
-
|
| 197 |
-
**Q: Can I change visibility later?**
|
| 198 |
-
A: Yes! You can switch between public/private anytime.
|
| 199 |
-
|
| 200 |
-
**Q: Does the token expire?**
|
| 201 |
-
A: Tokens can expire if you set an expiration date. Use "No expiration" for Spaces.
|
| 202 |
-
|
| 203 |
-
**Q: What if someone steals my token?**
|
| 204 |
-
A: They can only READ your model repos. Revoke and create a new token if compromised.
|
| 205 |
-
|
| 206 |
-
**Q: Can I use the same token for multiple Spaces?**
|
| 207 |
-
A: Yes! Same token works across all your Spaces.
|
| 208 |
-
|
| 209 |
-
---
|
| 210 |
-
|
| 211 |
-
**Recommendation:** Make the repo public for simplicity. The weights are already public via Google Drive anyway.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QUICKSTART.md
DELETED
|
@@ -1,270 +0,0 @@
|
|
| 1 |
-
# FoundationPose Quick Start Guide
|
| 2 |
-
|
| 3 |
-
## Overview
|
| 4 |
-
|
| 5 |
-
This Hugging Face Space provides two modes:
|
| 6 |
-
|
| 7 |
-
1. **Placeholder Mode** (default) - Returns empty results, useful for testing the API without GPU requirements
|
| 8 |
-
2. **Real Mode** - Uses actual FoundationPose model for 6D pose estimation (requires GPU and model weights)
|
| 9 |
-
|
| 10 |
-
## Testing Locally (Placeholder Mode)
|
| 11 |
-
|
| 12 |
-
The easiest way to test the API structure:
|
| 13 |
-
|
| 14 |
-
```bash
|
| 15 |
-
cd foundationpose
|
| 16 |
-
pip install -r requirements.txt
|
| 17 |
-
python app.py
|
| 18 |
-
```
|
| 19 |
-
|
| 20 |
-
Visit http://localhost:7860 to see the UI.
|
| 21 |
-
|
| 22 |
-
## Deploying to Hugging Face Spaces
|
| 23 |
-
|
| 24 |
-
### Option 1: Placeholder Mode (No Setup Required)
|
| 25 |
-
|
| 26 |
-
Just push to your Space:
|
| 27 |
-
|
| 28 |
-
```bash
|
| 29 |
-
cd foundationpose
|
| 30 |
-
git add .
|
| 31 |
-
git commit -m "Deploy FoundationPose Space"
|
| 32 |
-
git push
|
| 33 |
-
```
|
| 34 |
-
|
| 35 |
-
The Space will run in placeholder mode by default. This is useful for:
|
| 36 |
-
- Testing the API structure
|
| 37 |
-
- Developing client integrations
|
| 38 |
-
- Demos without GPU costs
|
| 39 |
-
|
| 40 |
-
### Option 2: Real FoundationPose (Requires Setup)
|
| 41 |
-
|
| 42 |
-
**Step 1: Clone FoundationPose Repository**
|
| 43 |
-
|
| 44 |
-
```bash
|
| 45 |
-
# Inside your local foundationpose directory
|
| 46 |
-
git clone https://github.com/NVlabs/FoundationPose.git
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
**Step 2: Download Model Weights**
|
| 50 |
-
|
| 51 |
-
Download weights from the official Google Drive:
|
| 52 |
-
https://drive.google.com/drive/folders/1GCyGE-LbFGgRC-FuGsF3a1zeBuzsQ1Da
|
| 53 |
-
|
| 54 |
-
Extract to:
|
| 55 |
-
```
|
| 56 |
-
foundationpose/weights/
|
| 57 |
-
├── 2023-10-28-18-33-37/ (refiner weights)
|
| 58 |
-
└── 2024-01-11-20-02-45/ (scorer weights)
|
| 59 |
-
```
|
| 60 |
-
|
| 61 |
-
**Step 3: Add Weights to Git LFS**
|
| 62 |
-
|
| 63 |
-
```bash
|
| 64 |
-
git lfs install
|
| 65 |
-
git lfs track "weights/**/*.pth"
|
| 66 |
-
git lfs track "weights/**/*.ckpt"
|
| 67 |
-
git add .gitattributes
|
| 68 |
-
git add weights/
|
| 69 |
-
git commit -m "Add model weights"
|
| 70 |
-
```
|
| 71 |
-
|
| 72 |
-
**Step 4: Enable Real Mode**
|
| 73 |
-
|
| 74 |
-
Add to your Space settings (or use .env file locally):
|
| 75 |
-
```
|
| 76 |
-
USE_REAL_MODEL=true
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
**Step 5: Push to HF**
|
| 80 |
-
|
| 81 |
-
```bash
|
| 82 |
-
git push
|
| 83 |
-
```
|
| 84 |
-
|
| 85 |
-
## Using the API
|
| 86 |
-
|
| 87 |
-
### Python Client
|
| 88 |
-
|
| 89 |
-
```python
|
| 90 |
-
from foundationpose.client import FoundationPoseClient
|
| 91 |
-
import cv2
|
| 92 |
-
import numpy as np
|
| 93 |
-
|
| 94 |
-
# Initialize client
|
| 95 |
-
client = FoundationPoseClient("https://gpue-foundationpose.hf.space")
|
| 96 |
-
|
| 97 |
-
# Load reference images
|
| 98 |
-
ref_images = []
|
| 99 |
-
for i in range(1, 16):
|
| 100 |
-
img = cv2.imread(f"reference/image_{i:03d}.jpg")
|
| 101 |
-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 102 |
-
ref_images.append(img)
|
| 103 |
-
|
| 104 |
-
# Register object
|
| 105 |
-
client.initialize("target_cube", ref_images)
|
| 106 |
-
|
| 107 |
-
# Estimate pose
|
| 108 |
-
query_img = cv2.imread("query.jpg")
|
| 109 |
-
query_img = cv2.cvtColor(query_img, cv2.COLOR_BGR2RGB)
|
| 110 |
-
|
| 111 |
-
poses = client.estimate_pose("target_cube", query_img)
|
| 112 |
-
print(f"Detected {len(poses)} poses")
|
| 113 |
-
for pose in poses:
|
| 114 |
-
print(f"Position: {pose['position']}")
|
| 115 |
-
print(f"Orientation: {pose['orientation']}")
|
| 116 |
-
print(f"Confidence: {pose['confidence']}")
|
| 117 |
-
```
|
| 118 |
-
|
| 119 |
-
### Direct HTTP API
|
| 120 |
-
|
| 121 |
-
```bash
|
| 122 |
-
# Initialize
|
| 123 |
-
curl -X POST https://gpue-foundationpose.hf.space/api/initialize \
|
| 124 |
-
-H "Content-Type: application/json" \
|
| 125 |
-
-d '{
|
| 126 |
-
"object_id": "target_cube",
|
| 127 |
-
"reference_images_b64": ["'$(base64 -w 0 ref1.jpg)'", "'$(base64 -w 0 ref2.jpg)'"],
|
| 128 |
-
"camera_intrinsics": "{\"fx\": 500, \"fy\": 500, \"cx\": 320, \"cy\": 240}"
|
| 129 |
-
}'
|
| 130 |
-
|
| 131 |
-
# Estimate
|
| 132 |
-
curl -X POST https://gpue-foundationpose.hf.space/api/estimate \
|
| 133 |
-
-H "Content-Type: application/json" \
|
| 134 |
-
-d '{
|
| 135 |
-
"object_id": "target_cube",
|
| 136 |
-
"query_image_b64": "'$(base64 -w 0 query.jpg)'"
|
| 137 |
-
}'
|
| 138 |
-
```
|
| 139 |
-
|
| 140 |
-
## Integration with robot-ml Training
|
| 141 |
-
|
| 142 |
-
Update `/training/nova_sim_trainer/perception/foundation_pose_wrapper.py`:
|
| 143 |
-
|
| 144 |
-
```python
|
| 145 |
-
from foundationpose.client import FoundationPoseClient
|
| 146 |
-
|
| 147 |
-
class FoundationPoseWrapper(PoseEstimator):
|
| 148 |
-
def __init__(self, api_url: str, tracked_objects: List[Dict], **kwargs):
|
| 149 |
-
super().__init__()
|
| 150 |
-
self.client = FoundationPoseClient(api_url)
|
| 151 |
-
|
| 152 |
-
# Initialize each tracked object
|
| 153 |
-
for obj_config in tracked_objects:
|
| 154 |
-
object_id = obj_config["object_id"]
|
| 155 |
-
ref_dir = Path(obj_config["reference_images_dir"])
|
| 156 |
-
|
| 157 |
-
# Load reference images
|
| 158 |
-
ref_images = []
|
| 159 |
-
for img_path in sorted(ref_dir.glob("*.jpg")):
|
| 160 |
-
img = cv2.imread(str(img_path))
|
| 161 |
-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 162 |
-
ref_images.append(img)
|
| 163 |
-
|
| 164 |
-
# Register object
|
| 165 |
-
self.client.initialize(object_id, ref_images)
|
| 166 |
-
logger.info(f"Registered {object_id} with {len(ref_images)} images")
|
| 167 |
-
|
| 168 |
-
def estimate_poses(self, frame, camera_intrinsics, scene_objects):
|
| 169 |
-
# Call API for pose estimation
|
| 170 |
-
poses = self.client.estimate_pose(
|
| 171 |
-
self.tracked_objects[0]["object_id"], # For now, single object
|
| 172 |
-
frame,
|
| 173 |
-
camera_intrinsics
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
-
# Convert to DetectedPose format
|
| 177 |
-
return [DetectedPose(**pose) for pose in poses]
|
| 178 |
-
```
|
| 179 |
-
|
| 180 |
-
Update `observations.yaml`:
|
| 181 |
-
|
| 182 |
-
```yaml
|
| 183 |
-
perception:
|
| 184 |
-
enabled: true
|
| 185 |
-
model: foundation_pose
|
| 186 |
-
api_url: https://gpue-foundationpose.hf.space
|
| 187 |
-
tracked_objects:
|
| 188 |
-
- object_id: target_cube
|
| 189 |
-
reference_images_dir: ./perception/reference/target_cube
|
| 190 |
-
```
|
| 191 |
-
|
| 192 |
-
## Performance Tips
|
| 193 |
-
|
| 194 |
-
### Cold Start Latency
|
| 195 |
-
- First request takes 15-30s (GPU allocation + model loading)
|
| 196 |
-
- Subsequent requests: 0.5-2s
|
| 197 |
-
|
| 198 |
-
### Keeping GPU Warm
|
| 199 |
-
Send periodic keep-alive requests:
|
| 200 |
-
```python
|
| 201 |
-
import time
|
| 202 |
-
import threading
|
| 203 |
-
|
| 204 |
-
def keep_warm():
|
| 205 |
-
while True:
|
| 206 |
-
try:
|
| 207 |
-
client.estimate_pose("target_cube", dummy_image)
|
| 208 |
-
except:
|
| 209 |
-
pass
|
| 210 |
-
time.sleep(60) # Every minute
|
| 211 |
-
|
| 212 |
-
threading.Thread(target=keep_warm, daemon=True).start()
|
| 213 |
-
```
|
| 214 |
-
|
| 215 |
-
### Batch Processing
|
| 216 |
-
For recorded episodes, process all frames in one session:
|
| 217 |
-
```python
|
| 218 |
-
# Initialize once
|
| 219 |
-
client.initialize("target_cube", ref_images)
|
| 220 |
-
|
| 221 |
-
# Process all frames
|
| 222 |
-
poses_list = []
|
| 223 |
-
for frame in frames:
|
| 224 |
-
poses = client.estimate_pose("target_cube", frame)
|
| 225 |
-
poses_list.append(poses)
|
| 226 |
-
```
|
| 227 |
-
|
| 228 |
-
## Troubleshooting
|
| 229 |
-
|
| 230 |
-
### Space shows "Placeholder mode"
|
| 231 |
-
- Set `USE_REAL_MODEL=true` in Space secrets
|
| 232 |
-
- Verify weights are uploaded correctly
|
| 233 |
-
- Check Space logs for errors
|
| 234 |
-
|
| 235 |
-
### "Model weights not found"
|
| 236 |
-
- Ensure weights are in `weights/` directory
|
| 237 |
-
- Check git-lfs tracked files: `git lfs ls-files`
|
| 238 |
-
- Re-upload if needed
|
| 239 |
-
|
| 240 |
-
### GPU timeout
|
| 241 |
-
- Increase `@spaces.GPU(duration=X)` in app.py
|
| 242 |
-
- Reduce image resolution
|
| 243 |
-
- Process fewer reference images
|
| 244 |
-
|
| 245 |
-
### Out of memory
|
| 246 |
-
- Use lower resolution images
|
| 247 |
-
- Process fewer objects simultaneously
|
| 248 |
-
- Request more GPU resources in Space settings
|
| 249 |
-
|
| 250 |
-
## Cost Optimization
|
| 251 |
-
|
| 252 |
-
ZeroGPU is free but has usage limits:
|
| 253 |
-
|
| 254 |
-
- **Development**: Use placeholder mode
|
| 255 |
-
- **Testing**: Enable real mode for specific tests only
|
| 256 |
-
- **Production**: Consider dedicated GPU deployment (RunPod, Modal, etc.)
|
| 257 |
-
|
| 258 |
-
## Next Steps
|
| 259 |
-
|
| 260 |
-
1. Test locally in placeholder mode
|
| 261 |
-
2. Upload weights for real mode
|
| 262 |
-
3. Integrate with robot-ml training pipeline
|
| 263 |
-
4. Monitor GPU usage and costs
|
| 264 |
-
5. Optimize batch processing for your use case
|
| 265 |
-
|
| 266 |
-
## Support
|
| 267 |
-
|
| 268 |
-
- **Issues**: https://github.com/gpuschel/robot-ml/issues
|
| 269 |
-
- **FoundationPose**: https://github.com/NVlabs/FoundationPose
|
| 270 |
-
- **HF Spaces**: https://huggingface.co/docs/hub/spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README_SETUP.md
DELETED
|
@@ -1,216 +0,0 @@
|
|
| 1 |
-
# FoundationPose Setup Guide
|
| 2 |
-
|
| 3 |
-
**Quick navigation to setup instructions:**
|
| 4 |
-
|
| 5 |
-
## 🎯 Choose Your Path
|
| 6 |
-
|
| 7 |
-
### Path 1: Test Without Weights (5 minutes)
|
| 8 |
-
|
| 9 |
-
Just want to test the API structure?
|
| 10 |
-
|
| 11 |
-
```bash
|
| 12 |
-
cd foundationpose
|
| 13 |
-
pip install -r requirements.txt
|
| 14 |
-
python app.py
|
| 15 |
-
```
|
| 16 |
-
|
| 17 |
-
✅ Works immediately
|
| 18 |
-
✅ No GPU needed
|
| 19 |
-
✅ Returns valid API responses (empty results)
|
| 20 |
-
✅ Perfect for developing client integrations
|
| 21 |
-
|
| 22 |
-
→ **No additional setup needed!**
|
| 23 |
-
|
| 24 |
-
---
|
| 25 |
-
|
| 26 |
-
### Path 2: Deploy with Real Weights (30 minutes)
|
| 27 |
-
|
| 28 |
-
Want actual 6D pose estimation?
|
| 29 |
-
|
| 30 |
-
**Step 1: Get Model Weights**
|
| 31 |
-
|
| 32 |
-
Option A: **Create HF Model Repo** (Recommended)
|
| 33 |
-
📖 **Guide:** [HF_MODEL_SETUP.md](HF_MODEL_SETUP.md) (Quick 5-min guide)
|
| 34 |
-
📖 **Detailed:** [UPLOAD_WEIGHTS.md](UPLOAD_WEIGHTS.md) (Full instructions)
|
| 35 |
-
|
| 36 |
-
```bash
|
| 37 |
-
# Quick version:
|
| 38 |
-
huggingface-cli login
|
| 39 |
-
huggingface-cli repo create foundationpose-weights --type model
|
| 40 |
-
huggingface-cli upload YOUR_USER/foundationpose-weights ./weights .
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
Option B: Manual Download (Not recommended)
|
| 44 |
-
- Download from Google Drive
|
| 45 |
-
- Use git-lfs to add to Space repo
|
| 46 |
-
- More complex, slower
|
| 47 |
-
|
| 48 |
-
**Step 2: Configure Space**
|
| 49 |
-
|
| 50 |
-
Add environment variables in Space settings:
|
| 51 |
-
```
|
| 52 |
-
FOUNDATIONPOSE_MODEL_REPO=YOUR_USER/foundationpose-weights
|
| 53 |
-
USE_HF_WEIGHTS=true
|
| 54 |
-
USE_REAL_MODEL=true
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
**Step 3: Deploy**
|
| 58 |
-
|
| 59 |
-
```bash
|
| 60 |
-
git push origin main
|
| 61 |
-
```
|
| 62 |
-
|
| 63 |
-
Done! Space will auto-download weights on first run.
|
| 64 |
-
|
| 65 |
-
---
|
| 66 |
-
|
| 67 |
-
## 📚 Documentation Index
|
| 68 |
-
|
| 69 |
-
| Document | Purpose | Read When |
|
| 70 |
-
|----------|---------|-----------|
|
| 71 |
-
| [HF_MODEL_SETUP.md](HF_MODEL_SETUP.md) | **Quick HF model repo setup** | Setting up weights (recommended way) |
|
| 72 |
-
| [UPLOAD_WEIGHTS.md](UPLOAD_WEIGHTS.md) | Detailed weight upload guide | Need step-by-step instructions |
|
| 73 |
-
| [QUICKSTART.md](QUICKSTART.md) | API usage & integration | Ready to use the API |
|
| 74 |
-
| [DEPLOYMENT.md](DEPLOYMENT.md) | Full deployment options | Want all the details |
|
| 75 |
-
| [STATUS.md](STATUS.md) | Complete project status | Want to know what's done/missing |
|
| 76 |
-
| [README.md](README.md) | Space homepage | First-time visitors |
|
| 77 |
-
|
| 78 |
-
---
|
| 79 |
-
|
| 80 |
-
## 🚀 Deployment Options Summary
|
| 81 |
-
|
| 82 |
-
### A. Placeholder Mode (Default)
|
| 83 |
-
|
| 84 |
-
```bash
|
| 85 |
-
# No setup needed
|
| 86 |
-
git push origin main
|
| 87 |
-
```
|
| 88 |
-
|
| 89 |
-
- Returns empty results
|
| 90 |
-
- Tests API structure
|
| 91 |
-
- No GPU costs
|
| 92 |
-
- Perfect for development
|
| 93 |
-
|
| 94 |
-
### B. Real Mode (Automatic Download)
|
| 95 |
-
|
| 96 |
-
```bash
|
| 97 |
-
# 1. Upload weights to HF model repo (see HF_MODEL_SETUP.md)
|
| 98 |
-
# 2. Set Space environment variables:
|
| 99 |
-
# FOUNDATIONPOSE_MODEL_REPO=YOUR_USER/foundationpose-weights
|
| 100 |
-
# USE_HF_WEIGHTS=true
|
| 101 |
-
# USE_REAL_MODEL=true
|
| 102 |
-
# 3. Deploy
|
| 103 |
-
git push origin main
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
- Automatic weight download
|
| 107 |
-
- Real pose estimation
|
| 108 |
-
- ZeroGPU inference
|
| 109 |
-
- Production-ready
|
| 110 |
-
|
| 111 |
-
### C. Real Mode (Manual Weights)
|
| 112 |
-
|
| 113 |
-
```bash
|
| 114 |
-
# 1. Download weights manually
|
| 115 |
-
# 2. Add with git-lfs
|
| 116 |
-
git lfs track "weights/**"
|
| 117 |
-
git add weights/
|
| 118 |
-
git commit -m "Add weights"
|
| 119 |
-
# 3. Set USE_REAL_MODEL=true
|
| 120 |
-
git push origin main
|
| 121 |
-
```
|
| 122 |
-
|
| 123 |
-
- Weights included in Space
|
| 124 |
-
- Slower deployments
|
| 125 |
-
- Larger Space size
|
| 126 |
-
- Not recommended
|
| 127 |
-
|
| 128 |
-
---
|
| 129 |
-
|
| 130 |
-
## 🔗 Integration with robot-ml
|
| 131 |
-
|
| 132 |
-
Once your Space is running:
|
| 133 |
-
|
| 134 |
-
**1. Update wrapper:**
|
| 135 |
-
```python
|
| 136 |
-
from foundationpose.client import FoundationPoseClient
|
| 137 |
-
|
| 138 |
-
client = FoundationPoseClient("https://YOUR_USER-foundationpose.hf.space")
|
| 139 |
-
```
|
| 140 |
-
|
| 141 |
-
**2. Update config:**
|
| 142 |
-
```yaml
|
| 143 |
-
perception:
|
| 144 |
-
enabled: true
|
| 145 |
-
model: foundation_pose
|
| 146 |
-
api_url: https://YOUR_USER-foundationpose.hf.space
|
| 147 |
-
```
|
| 148 |
-
|
| 149 |
-
**Full integration code:** See [QUICKSTART.md](QUICKSTART.md#integration-with-robot-ml)
|
| 150 |
-
|
| 151 |
-
---
|
| 152 |
-
|
| 153 |
-
## ❓ FAQ
|
| 154 |
-
|
| 155 |
-
**Q: Do I need a GPU?**
|
| 156 |
-
A: No. ZeroGPU allocates GPU on-demand when needed.
|
| 157 |
-
|
| 158 |
-
**Q: How much does it cost?**
|
| 159 |
-
A: ZeroGPU is free with usage limits. Placeholder mode uses no GPU.
|
| 160 |
-
|
| 161 |
-
**Q: Can I use someone else's weights?**
|
| 162 |
-
A: Yes! If someone has a public model repo: `FOUNDATIONPOSE_MODEL_REPO=their-username/foundationpose-weights`
|
| 163 |
-
|
| 164 |
-
**Q: How big are the weights?**
|
| 165 |
-
A: ~1.8GB total (900MB refiner + 900MB scorer)
|
| 166 |
-
|
| 167 |
-
**Q: Where do I get the weights?**
|
| 168 |
-
A: Download from [Google Drive](https://drive.google.com/drive/folders/1GCyGE-LbFGgRC-FuGsF3a1zeBuzsQ1Da) then upload to HF model repo.
|
| 169 |
-
|
| 170 |
-
**Q: Can I test locally?**
|
| 171 |
-
A: Yes! `python test_local.py` tests everything locally first.
|
| 172 |
-
|
| 173 |
-
**Q: What if weight download fails?**
|
| 174 |
-
A: Space will run in placeholder mode automatically. Check logs for errors.
|
| 175 |
-
|
| 176 |
-
---
|
| 177 |
-
|
| 178 |
-
## 🎯 Recommended Workflow
|
| 179 |
-
|
| 180 |
-
```
|
| 181 |
-
1. Test locally first
|
| 182 |
-
→ python test_local.py
|
| 183 |
-
|
| 184 |
-
2. Deploy placeholder mode
|
| 185 |
-
→ Test Space works
|
| 186 |
-
|
| 187 |
-
3. Create HF model repo
|
| 188 |
-
→ Upload weights
|
| 189 |
-
→ See HF_MODEL_SETUP.md
|
| 190 |
-
|
| 191 |
-
4. Enable real mode
|
| 192 |
-
→ Set environment variables
|
| 193 |
-
→ Space auto-downloads weights
|
| 194 |
-
|
| 195 |
-
5. Integrate with robot-ml
|
| 196 |
-
→ See QUICKSTART.md
|
| 197 |
-
```
|
| 198 |
-
|
| 199 |
-
---
|
| 200 |
-
|
| 201 |
-
## 🆘 Getting Help
|
| 202 |
-
|
| 203 |
-
- **General questions:** See [QUICKSTART.md](QUICKSTART.md)
|
| 204 |
-
- **Deployment issues:** See [DEPLOYMENT.md](DEPLOYMENT.md)
|
| 205 |
-
- **Weight upload:** See [UPLOAD_WEIGHTS.md](UPLOAD_WEIGHTS.md) or [HF_MODEL_SETUP.md](HF_MODEL_SETUP.md)
|
| 206 |
-
- **Project status:** See [STATUS.md](STATUS.md)
|
| 207 |
-
- **API usage:** See [QUICKSTART.md](QUICKSTART.md)
|
| 208 |
-
|
| 209 |
-
---
|
| 210 |
-
|
| 211 |
-
**Start here:**
|
| 212 |
-
→ Test locally: `python test_local.py`
|
| 213 |
-
→ Want real weights: [HF_MODEL_SETUP.md](HF_MODEL_SETUP.md)
|
| 214 |
-
→ Deploy: `git push origin main`
|
| 215 |
-
|
| 216 |
-
That's it! 🎉
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STATUS.md
DELETED
|
@@ -1,383 +0,0 @@
|
|
| 1 |
-
# FoundationPose Deployment - Current Status
|
| 2 |
-
|
| 3 |
-
**Last Updated:** 2026-01-28
|
| 4 |
-
**Repository:** `/Users/georgpuschel/repos/robot-ml/foundationpose/`
|
| 5 |
-
**Hugging Face Space:** https://huggingface.co/spaces/gpue/foundationpose
|
| 6 |
-
|
| 7 |
-
---
|
| 8 |
-
|
| 9 |
-
## 📦 What's Been Completed
|
| 10 |
-
|
| 11 |
-
### Core Files Created
|
| 12 |
-
|
| 13 |
-
1. **app.py** (570 lines)
|
| 14 |
-
- Complete Gradio application with ZeroGPU integration
|
| 15 |
-
- Dual mode: Placeholder (default) and Real FoundationPose
|
| 16 |
-
- REST API endpoints: `/api/initialize` and `/api/estimate`
|
| 17 |
-
- Web UI with tabs for initialization, estimation, and API docs
|
| 18 |
-
- Environment variable `USE_REAL_MODEL` controls mode
|
| 19 |
-
|
| 20 |
-
2. **estimator.py** (350+ lines)
|
| 21 |
-
- FoundationPoseEstimator class wrapping the real FoundationPose API
|
| 22 |
-
- Methods: `register_object()`, `estimate_pose()`, `reset_tracking()`
|
| 23 |
-
- Handles camera intrinsics, depth images, and segmentation masks
|
| 24 |
-
- Quaternion and rotation matrix conversions
|
| 25 |
-
- Mesh loading and reconstruction (placeholder for BundleSDF)
|
| 26 |
-
|
| 27 |
-
3. **client.py** (200+ lines)
|
| 28 |
-
- Python client for calling the API from robot-ml
|
| 29 |
-
- FoundationPoseClient class with initialize() and estimate_pose()
|
| 30 |
-
- Image encoding/decoding utilities
|
| 31 |
-
- Example usage code
|
| 32 |
-
|
| 33 |
-
4. **requirements.txt**
|
| 34 |
-
- Core dependencies: gradio, spaces, torch, opencv-python
|
| 35 |
-
- 3D vision: trimesh, pyrender, scikit-image
|
| 36 |
-
- Placeholder for FoundationPose installation
|
| 37 |
-
|
| 38 |
-
5. **Dockerfile**
|
| 39 |
-
- CUDA 12.1 base image
|
| 40 |
-
- System dependencies (eigen3, OpenGL, etc.)
|
| 41 |
-
- FoundationPose repository clone and build
|
| 42 |
-
- NVDiffRast, Kaolin, PyTorch3D installation
|
| 43 |
-
|
| 44 |
-
6. **download_weights.py**
|
| 45 |
-
- Script to check for and download model weights
|
| 46 |
-
- Instructions for manual weight setup
|
| 47 |
-
- Git-LFS integration guide
|
| 48 |
-
|
| 49 |
-
7. **deploy.sh**
|
| 50 |
-
- Interactive deployment script
|
| 51 |
-
- Checks for weights and git status
|
| 52 |
-
- Offers placeholder vs real mode deployment
|
| 53 |
-
- Guides through git-lfs setup
|
| 54 |
-
|
| 55 |
-
8. **Documentation**
|
| 56 |
-
- README.md (updated with full details)
|
| 57 |
-
- DEPLOYMENT.md (step-by-step deployment guide)
|
| 58 |
-
- QUICKSTART.md (quick start for both modes)
|
| 59 |
-
- STATUS.md (this file)
|
| 60 |
-
|
| 61 |
-
9. **.gitignore**
|
| 62 |
-
- Python cache files
|
| 63 |
-
- Virtual environments
|
| 64 |
-
- Model weights (for git-lfs)
|
| 65 |
-
- Test images
|
| 66 |
-
|
| 67 |
-
---
|
| 68 |
-
|
| 69 |
-
## 🎯 How It Works
|
| 70 |
-
|
| 71 |
-
### Placeholder Mode (Default)
|
| 72 |
-
|
| 73 |
-
- **Purpose**: API testing without GPU requirements
|
| 74 |
-
- **Behavior**: Returns empty pose results with success=true
|
| 75 |
-
- **Use Cases**:
|
| 76 |
-
- Developing client integrations
|
| 77 |
-
- Testing API structure
|
| 78 |
-
- Demos without GPU costs
|
| 79 |
-
|
| 80 |
-
### Real Mode (Requires Setup)
|
| 81 |
-
|
| 82 |
-
- **Purpose**: Actual 6D pose estimation
|
| 83 |
-
- **Requirements**:
|
| 84 |
-
- Model weights in `weights/` directory
|
| 85 |
-
- FoundationPose repository cloned
|
| 86 |
-
- Environment variable `USE_REAL_MODEL=true`
|
| 87 |
-
- **Behavior**: Uses actual FoundationPose inference
|
| 88 |
-
- **Use Cases**:
|
| 89 |
-
- Production pose estimation
|
| 90 |
-
- Validation and testing with real data
|
| 91 |
-
- Integration with robot-ml training
|
| 92 |
-
|
| 93 |
-
---
|
| 94 |
-
|
| 95 |
-
## 🚀 Deployment Options
|
| 96 |
-
|
| 97 |
-
### Option 1: Test Locally (Placeholder)
|
| 98 |
-
|
| 99 |
-
```bash
|
| 100 |
-
cd foundationpose
|
| 101 |
-
pip install -r requirements.txt
|
| 102 |
-
python app.py
|
| 103 |
-
# Visit http://localhost:7860
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
### Option 2: Deploy to HF (Placeholder)
|
| 107 |
-
|
| 108 |
-
```bash
|
| 109 |
-
./deploy.sh
|
| 110 |
-
# Or manually:
|
| 111 |
-
git add .
|
| 112 |
-
git commit -m "Deploy FoundationPose Space"
|
| 113 |
-
git push origin main
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
-
### Option 3: Deploy to HF (Real Mode)
|
| 117 |
-
|
| 118 |
-
**Requirements:**
|
| 119 |
-
1. Download weights from Google Drive
|
| 120 |
-
2. Set up git-lfs
|
| 121 |
-
3. Enable USE_REAL_MODEL=true
|
| 122 |
-
|
| 123 |
-
**Steps:**
|
| 124 |
-
```bash
|
| 125 |
-
# 1. Download weights (manual step)
|
| 126 |
-
# Visit: https://drive.google.com/drive/folders/1GCyGE-LbFGgRC-FuGsF3a1zeBuzsQ1Da
|
| 127 |
-
# Extract to: weights/2023-10-28-18-33-37/ and weights/2024-01-11-20-02-45/
|
| 128 |
-
|
| 129 |
-
# 2. Set up git-lfs
|
| 130 |
-
git lfs install
|
| 131 |
-
git lfs track "weights/**"
|
| 132 |
-
git add .gitattributes
|
| 133 |
-
|
| 134 |
-
# 3. Add weights
|
| 135 |
-
git add weights/
|
| 136 |
-
git commit -m "Add model weights"
|
| 137 |
-
|
| 138 |
-
# 4. Deploy
|
| 139 |
-
git push origin main
|
| 140 |
-
|
| 141 |
-
# 5. Set Space secret: USE_REAL_MODEL=true
|
| 142 |
-
```
|
| 143 |
-
|
| 144 |
-
---
|
| 145 |
-
|
| 146 |
-
## 🔗 Integration with robot-ml
|
| 147 |
-
|
| 148 |
-
### Update FoundationPose Wrapper
|
| 149 |
-
|
| 150 |
-
Edit `/training/nova_sim_trainer/perception/foundation_pose_wrapper.py`:
|
| 151 |
-
|
| 152 |
-
```python
|
| 153 |
-
from foundationpose.client import FoundationPoseClient
|
| 154 |
-
from pathlib import Path
|
| 155 |
-
import cv2
|
| 156 |
-
|
| 157 |
-
class FoundationPoseWrapper(PoseEstimator):
|
| 158 |
-
def __init__(self, api_url: str, tracked_objects: List[Dict], **kwargs):
|
| 159 |
-
super().__init__()
|
| 160 |
-
self.client = FoundationPoseClient(api_url)
|
| 161 |
-
self.object_ids = []
|
| 162 |
-
|
| 163 |
-
# Initialize each tracked object
|
| 164 |
-
for obj_config in tracked_objects:
|
| 165 |
-
if not obj_config.get("enabled", True):
|
| 166 |
-
continue
|
| 167 |
-
|
| 168 |
-
object_id = obj_config["object_id"]
|
| 169 |
-
ref_dir = Path(obj_config["reference_images_dir"])
|
| 170 |
-
|
| 171 |
-
# Load reference images
|
| 172 |
-
ref_images = []
|
| 173 |
-
for img_path in sorted(ref_dir.glob("*.jpg")):
|
| 174 |
-
img = cv2.imread(str(img_path))
|
| 175 |
-
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 176 |
-
ref_images.append(img)
|
| 177 |
-
|
| 178 |
-
# Register object with API
|
| 179 |
-
logger.info(f"Registering {object_id} with {len(ref_images)} images...")
|
| 180 |
-
self.client.initialize(object_id, ref_images)
|
| 181 |
-
self.object_ids.append(object_id)
|
| 182 |
-
|
| 183 |
-
def estimate_poses(self, frame, camera_intrinsics, scene_objects):
|
| 184 |
-
detected_poses = []
|
| 185 |
-
|
| 186 |
-
for object_id in self.object_ids:
|
| 187 |
-
poses = self.client.estimate_pose(object_id, frame, camera_intrinsics)
|
| 188 |
-
|
| 189 |
-
for pose in poses:
|
| 190 |
-
detected_poses.append(DetectedPose(
|
| 191 |
-
object_id=pose["object_id"],
|
| 192 |
-
position=pose["position"],
|
| 193 |
-
orientation=pose["orientation"],
|
| 194 |
-
confidence=pose["confidence"],
|
| 195 |
-
timestamp=0.0,
|
| 196 |
-
dimensions=tuple(pose.get("dimensions", [0.1, 0.1, 0.1]))
|
| 197 |
-
))
|
| 198 |
-
|
| 199 |
-
return detected_poses
|
| 200 |
-
```
|
| 201 |
-
|
| 202 |
-
### Update Configuration
|
| 203 |
-
|
| 204 |
-
Edit `/training/observations.yaml`:
|
| 205 |
-
|
| 206 |
-
```yaml
|
| 207 |
-
perception:
|
| 208 |
-
enabled: true
|
| 209 |
-
model: foundation_pose
|
| 210 |
-
api_url: https://gpue-foundationpose.hf.space # Your deployed Space URL
|
| 211 |
-
camera: aux_top
|
| 212 |
-
inference_fps: 5
|
| 213 |
-
|
| 214 |
-
tracked_objects:
|
| 215 |
-
- object_id: target_cube
|
| 216 |
-
scene_object_name: t_object
|
| 217 |
-
enabled: true
|
| 218 |
-
reference_images_dir: ./perception/reference/target_cube
|
| 219 |
-
dimensions: [0.1, 0.1, 0.1]
|
| 220 |
-
```
|
| 221 |
-
|
| 222 |
-
---
|
| 223 |
-
|
| 224 |
-
## ⚠️ What's NOT Done Yet
|
| 225 |
-
|
| 226 |
-
### Missing Pieces
|
| 227 |
-
|
| 228 |
-
1. **Model Weights**
|
| 229 |
-
- Not included in repo (too large)
|
| 230 |
-
- Must be downloaded manually
|
| 231 |
-
- Requires git-lfs setup
|
| 232 |
-
|
| 233 |
-
2. **FoundationPose Repository**
|
| 234 |
-
- Not included (git submodule or clone needed)
|
| 235 |
-
- C++ extensions need to be built
|
| 236 |
-
- Tested only with placeholder code
|
| 237 |
-
|
| 238 |
-
3. **BundleSDF Integration**
|
| 239 |
-
- Mesh reconstruction not implemented
|
| 240 |
-
- Currently uses placeholder cube mesh
|
| 241 |
-
- Needed for model-free mode
|
| 242 |
-
|
| 243 |
-
4. **Segmentation**
|
| 244 |
-
- Object segmentation uses placeholder mask
|
| 245 |
-
- Should integrate SAM (Segment Anything Model)
|
| 246 |
-
- Optional but improves accuracy
|
| 247 |
-
|
| 248 |
-
5. **Pose Visualization**
|
| 249 |
-
- Estimation results don't show overlays yet
|
| 250 |
-
- TODO: Render detected pose on query image
|
| 251 |
-
- Would improve debugging
|
| 252 |
-
|
| 253 |
-
### Testing Status
|
| 254 |
-
|
| 255 |
-
- ✅ Placeholder mode tested locally
|
| 256 |
-
- ⚠️ Real mode NOT tested (no weights)
|
| 257 |
-
- ⚠️ API integration NOT tested end-to-end
|
| 258 |
-
- ⚠️ ZeroGPU behavior unknown (not deployed yet)
|
| 259 |
-
|
| 260 |
-
---
|
| 261 |
-
|
| 262 |
-
## 📊 Performance Expectations
|
| 263 |
-
|
| 264 |
-
### ZeroGPU Characteristics
|
| 265 |
-
|
| 266 |
-
- **Cold Start**: 15-30 seconds (GPU allocation + model loading)
|
| 267 |
-
- **Warm Inference**: 0.5-2 seconds per query
|
| 268 |
-
- **Free Tier**: Limited monthly usage
|
| 269 |
-
- **Timeout**: GPU allocation lasts for duration specified in decorator
|
| 270 |
-
|
| 271 |
-
### robot-ml Training Integration
|
| 272 |
-
|
| 273 |
-
**Not suitable for real-time training loop (30 Hz):**
|
| 274 |
-
- 5 Hz perception requires 200ms per frame
|
| 275 |
-
- ZeroGPU latency: 500ms-2s warm, 15-30s cold
|
| 276 |
-
- ❌ Too slow for synchronous training
|
| 277 |
-
|
| 278 |
-
**Suitable for:**
|
| 279 |
-
- ✅ Batch processing recorded episodes
|
| 280 |
-
- ✅ Validation and testing
|
| 281 |
-
- ✅ Demos and visualization
|
| 282 |
-
- ✅ Reference data collection
|
| 283 |
-
|
| 284 |
-
**Recommendation:**
|
| 285 |
-
- Use dummy estimator during training (reads ground truth from sim)
|
| 286 |
-
- Use FoundationPose API for validation/testing only
|
| 287 |
-
- Consider local GPU deployment for production
|
| 288 |
-
|
| 289 |
-
---
|
| 290 |
-
|
| 291 |
-
## 📝 Next Steps
|
| 292 |
-
|
| 293 |
-
### Immediate (Before Deployment)
|
| 294 |
-
|
| 295 |
-
1. **Test Locally**
|
| 296 |
-
```bash
|
| 297 |
-
cd foundationpose
|
| 298 |
-
python app.py
|
| 299 |
-
# Test UI at http://localhost:7860
|
| 300 |
-
```
|
| 301 |
-
|
| 302 |
-
2. **Deploy Placeholder Mode**
|
| 303 |
-
```bash
|
| 304 |
-
./deploy.sh
|
| 305 |
-
# Choose "N" for real mode
|
| 306 |
-
```
|
| 307 |
-
|
| 308 |
-
3. **Verify Space Works**
|
| 309 |
-
- Visit https://huggingface.co/spaces/gpue/foundationpose
|
| 310 |
-
- Test initialization with test images
|
| 311 |
-
- Check logs for errors
|
| 312 |
-
|
| 313 |
-
### Short Term (With Weights)
|
| 314 |
-
|
| 315 |
-
1. **Download Model Weights**
|
| 316 |
-
- Get from Google Drive (see DEPLOYMENT.md)
|
| 317 |
-
- Extract to `weights/` directory
|
| 318 |
-
|
| 319 |
-
2. **Test Real Mode Locally**
|
| 320 |
-
```bash
|
| 321 |
-
export USE_REAL_MODEL=true
|
| 322 |
-
python app.py
|
| 323 |
-
# Upload real reference images
|
| 324 |
-
# Test pose estimation
|
| 325 |
-
```
|
| 326 |
-
|
| 327 |
-
3. **Deploy Real Mode**
|
| 328 |
-
```bash
|
| 329 |
-
# Set up git-lfs
|
| 330 |
-
git lfs track "weights/**"
|
| 331 |
-
git add .gitattributes weights/
|
| 332 |
-
git commit -m "Add model weights"
|
| 333 |
-
git push
|
| 334 |
-
|
| 335 |
-
# Set Space secret: USE_REAL_MODEL=true
|
| 336 |
-
```
|
| 337 |
-
|
| 338 |
-
### Long Term (Production)
|
| 339 |
-
|
| 340 |
-
1. **Optimize Performance**
|
| 341 |
-
- Implement batch inference
|
| 342 |
-
- Add caching for frequently used objects
|
| 343 |
-
- Tune GPU duration parameters
|
| 344 |
-
|
| 345 |
-
2. **Improve Accuracy**
|
| 346 |
-
- Integrate SAM for segmentation
|
| 347 |
-
- Add depth image support
|
| 348 |
-
- Implement BundleSDF reconstruction
|
| 349 |
-
|
| 350 |
-
3. **Production Deployment**
|
| 351 |
-
- Consider dedicated GPU (RunPod, Modal, etc.)
|
| 352 |
-
- Set up monitoring and logging
|
| 353 |
-
- Implement retry logic and error handling
|
| 354 |
-
|
| 355 |
-
---
|
| 356 |
-
|
| 357 |
-
## 📚 Reference Links
|
| 358 |
-
|
| 359 |
-
- **FoundationPose GitHub**: https://github.com/NVlabs/FoundationPose
|
| 360 |
-
- **Research Paper**: https://arxiv.org/abs/2312.08344
|
| 361 |
-
- **Model Weights**: https://drive.google.com/drive/folders/1GCyGE-LbFGgRC-FuGsF3a1zeBuzsQ1Da
|
| 362 |
-
- **HF Spaces Docs**: https://huggingface.co/docs/hub/spaces
|
| 363 |
-
- **ZeroGPU Docs**: https://huggingface.co/docs/hub/spaces-gpus-zerogpu
|
| 364 |
-
- **Gradio Docs**: https://www.gradio.app/docs
|
| 365 |
-
|
| 366 |
-
---
|
| 367 |
-
|
| 368 |
-
## 🤝 Citation
|
| 369 |
-
|
| 370 |
-
If you use this in your work:
|
| 371 |
-
|
| 372 |
-
```bibtex
|
| 373 |
-
@inproceedings{wen2023foundationpose,
|
| 374 |
-
title={FoundationPose: Unified 6D Pose Estimation and Tracking of Novel Objects},
|
| 375 |
-
author={Wen, Bowen and Yang, Wei and Kautz, Jan and Birchfield, Stan},
|
| 376 |
-
booktitle={CVPR},
|
| 377 |
-
year={2024}
|
| 378 |
-
}
|
| 379 |
-
```
|
| 380 |
-
|
| 381 |
-
---
|
| 382 |
-
|
| 383 |
-
**Summary:** The FoundationPose Space is fully set up and ready to deploy. It defaults to placeholder mode (no GPU needed) for testing the API structure. To enable real pose estimation, you need to manually download the model weights and set USE_REAL_MODEL=true. The integration code for robot-ml is ready but untested without the actual weights.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPLOAD_WEIGHTS.md
DELETED
|
@@ -1,328 +0,0 @@
|
|
| 1 |
-
# How to Upload FoundationPose Weights to Hugging Face
|
| 2 |
-
|
| 3 |
-
This guide shows you how to host FoundationPose model weights in a Hugging Face model repository, which is much better than using git-lfs in your Space.
|
| 4 |
-
|
| 5 |
-
## Why Use a Model Repository?
|
| 6 |
-
|
| 7 |
-
✅ **Benefits:**
|
| 8 |
-
- Designed for large files (GB+)
|
| 9 |
-
- Fast CDN downloads
|
| 10 |
-
- Version control for weights
|
| 11 |
-
- Share weights across multiple Spaces
|
| 12 |
-
- No need for git-lfs in Space repo
|
| 13 |
-
- Better download performance
|
| 14 |
-
|
| 15 |
-
## Step-by-Step Guide
|
| 16 |
-
|
| 17 |
-
### 1. Download Official Weights
|
| 18 |
-
|
| 19 |
-
First, get the official FoundationPose weights from Google Drive:
|
| 20 |
-
|
| 21 |
-
**Download Link:** https://drive.google.com/drive/folders/1GCyGE-LbFGgRC-FuGsF3a1zeBuzsQ1Da
|
| 22 |
-
|
| 23 |
-
Download these two folders:
|
| 24 |
-
- `2023-10-28-18-33-37/` (refiner weights, ~900MB)
|
| 25 |
-
- `2024-01-11-20-02-45/` (scorer weights, ~900MB)
|
| 26 |
-
|
| 27 |
-
Save them locally in a directory structure like:
|
| 28 |
-
```
|
| 29 |
-
foundationpose-weights/
|
| 30 |
-
├── 2023-10-28-18-33-37/
|
| 31 |
-
│ ├── model.pth
|
| 32 |
-
│ └── ...
|
| 33 |
-
└── 2024-01-11-20-02-45/
|
| 34 |
-
├── model.pth
|
| 35 |
-
└── ...
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
### 2. Create Hugging Face Model Repository
|
| 39 |
-
|
| 40 |
-
**Option A: Using the Web Interface**
|
| 41 |
-
|
| 42 |
-
1. Go to https://huggingface.co/new
|
| 43 |
-
2. Choose "Model" (not Space or Dataset)
|
| 44 |
-
3. Set owner to your username (e.g., `gpue`)
|
| 45 |
-
4. Set name: `foundationpose-weights`
|
| 46 |
-
5. Make it **Public** (so your Space can download it) or Private (requires token)
|
| 47 |
-
6. Click "Create model"
|
| 48 |
-
|
| 49 |
-
**Option B: Using the CLI**
|
| 50 |
-
|
| 51 |
-
```bash
|
| 52 |
-
pip install huggingface_hub
|
| 53 |
-
huggingface-cli login # Enter your token
|
| 54 |
-
|
| 55 |
-
# Create repo
|
| 56 |
-
huggingface-cli repo create foundationpose-weights --type model
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
### 3. Upload Weights to Model Repository
|
| 60 |
-
|
| 61 |
-
**Option A: Using the Web Interface**
|
| 62 |
-
|
| 63 |
-
1. Go to your model repo: `https://huggingface.co/YOUR_USERNAME/foundationpose-weights`
|
| 64 |
-
2. Click "Files" → "Add file" → "Upload files"
|
| 65 |
-
3. Drag and drop the two weight folders
|
| 66 |
-
4. Click "Commit changes"
|
| 67 |
-
|
| 68 |
-
⚠️ **Note:** Web upload may be slow for large files. Use CLI for better experience.
|
| 69 |
-
|
| 70 |
-
**Option B: Using the CLI (Recommended)**
|
| 71 |
-
|
| 72 |
-
```bash
|
| 73 |
-
# From the directory containing your weight folders
|
| 74 |
-
huggingface-cli upload YOUR_USERNAME/foundationpose-weights ./2023-10-28-18-33-37 2023-10-28-18-33-37
|
| 75 |
-
huggingface-cli upload YOUR_USERNAME/foundationpose-weights ./2024-01-11-20-02-45 2024-01-11-20-02-45
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
**Option C: Using Python Script**
|
| 79 |
-
|
| 80 |
-
```python
|
| 81 |
-
from huggingface_hub import HfApi
|
| 82 |
-
from pathlib import Path
|
| 83 |
-
|
| 84 |
-
api = HfApi()
|
| 85 |
-
repo_id = "YOUR_USERNAME/foundationpose-weights"
|
| 86 |
-
weights_dir = Path("./foundationpose-weights")
|
| 87 |
-
|
| 88 |
-
print("Uploading weights to Hugging Face...")
|
| 89 |
-
|
| 90 |
-
# Upload entire directory
|
| 91 |
-
api.upload_folder(
|
| 92 |
-
folder_path=str(weights_dir),
|
| 93 |
-
repo_id=repo_id,
|
| 94 |
-
repo_type="model"
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
print("✓ Upload complete!")
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
### 4. Add Model Card (README)
|
| 101 |
-
|
| 102 |
-
Create a `README.md` in your model repo to document the weights:
|
| 103 |
-
|
| 104 |
-
```markdown
|
| 105 |
-
---
|
| 106 |
-
license: cc-by-nc-4.0
|
| 107 |
-
tags:
|
| 108 |
-
- computer-vision
|
| 109 |
-
- 6d-pose-estimation
|
| 110 |
-
- object-detection
|
| 111 |
-
- robotics
|
| 112 |
-
---
|
| 113 |
-
|
| 114 |
-
# FoundationPose Model Weights
|
| 115 |
-
|
| 116 |
-
Pre-trained weights for [FoundationPose](https://github.com/NVlabs/FoundationPose) 6D object pose estimation model.
|
| 117 |
-
|
| 118 |
-
## Model Details
|
| 119 |
-
|
| 120 |
-
- **Refiner weights:** `2023-10-28-18-33-37/`
|
| 121 |
-
- **Scorer weights:** `2024-01-11-20-02-45/`
|
| 122 |
-
- **Source:** [Official FoundationPose release](https://github.com/NVlabs/FoundationPose)
|
| 123 |
-
|
| 124 |
-
## Usage
|
| 125 |
-
|
| 126 |
-
```python
|
| 127 |
-
from huggingface_hub import snapshot_download
|
| 128 |
-
|
| 129 |
-
# Download all weights
|
| 130 |
-
snapshot_download(
|
| 131 |
-
repo_id="YOUR_USERNAME/foundationpose-weights",
|
| 132 |
-
local_dir="./weights"
|
| 133 |
-
)
|
| 134 |
-
```
|
| 135 |
-
|
| 136 |
-
## Citation
|
| 137 |
-
|
| 138 |
-
```bibtex
|
| 139 |
-
@inproceedings{wen2023foundationpose,
|
| 140 |
-
title={FoundationPose: Unified 6D Pose Estimation and Tracking of Novel Objects},
|
| 141 |
-
author={Wen, Bowen and Yang, Wei and Kautz, Jan and Birchfield, Stan},
|
| 142 |
-
booktitle={CVPR},
|
| 143 |
-
year={2024}
|
| 144 |
-
}
|
| 145 |
-
```
|
| 146 |
-
|
| 147 |
-
## License
|
| 148 |
-
|
| 149 |
-
These weights are from the official FoundationPose release and subject to NVIDIA's license terms.
|
| 150 |
-
```
|
| 151 |
-
|
| 152 |
-
### 5. Configure Your Space to Use the Model Repo
|
| 153 |
-
|
| 154 |
-
Update your Space's environment variables (Settings → Variables and secrets):
|
| 155 |
-
|
| 156 |
-
```
|
| 157 |
-
FOUNDATIONPOSE_MODEL_REPO=YOUR_USERNAME/foundationpose-weights
|
| 158 |
-
USE_HF_WEIGHTS=true
|
| 159 |
-
USE_REAL_MODEL=true
|
| 160 |
-
```
|
| 161 |
-
|
| 162 |
-
Or set in your Space's Dockerfile/code:
|
| 163 |
-
|
| 164 |
-
```python
|
| 165 |
-
import os
|
| 166 |
-
os.environ["FOUNDATIONPOSE_MODEL_REPO"] = "gpue/foundationpose-weights"
|
| 167 |
-
os.environ["USE_HF_WEIGHTS"] = "true"
|
| 168 |
-
```
|
| 169 |
-
|
| 170 |
-
### 6. Test the Setup
|
| 171 |
-
|
| 172 |
-
**Test locally:**
|
| 173 |
-
|
| 174 |
-
```bash
|
| 175 |
-
cd foundationpose
|
| 176 |
-
|
| 177 |
-
# Set environment variables
|
| 178 |
-
export FOUNDATIONPOSE_MODEL_REPO="YOUR_USERNAME/foundationpose-weights"
|
| 179 |
-
export USE_HF_WEIGHTS="true"
|
| 180 |
-
|
| 181 |
-
# Download weights
|
| 182 |
-
python download_weights.py
|
| 183 |
-
|
| 184 |
-
# Should see:
|
| 185 |
-
# ✓ Download complete!
|
| 186 |
-
# ✓ Model weights found locally!
|
| 187 |
-
```
|
| 188 |
-
|
| 189 |
-
**Test in Space:**
|
| 190 |
-
|
| 191 |
-
After pushing to HF Spaces, check the build logs:
|
| 192 |
-
1. Go to your Space → Logs
|
| 193 |
-
2. Look for "Downloading from Hugging Face Model Repository"
|
| 194 |
-
3. Should see "✓ Download complete!"
|
| 195 |
-
|
| 196 |
-
### 7. Verify Weights Are Correct
|
| 197 |
-
|
| 198 |
-
Check that the downloaded structure matches:
|
| 199 |
-
|
| 200 |
-
```bash
|
| 201 |
-
ls -R weights/
|
| 202 |
-
|
| 203 |
-
# Should show:
|
| 204 |
-
# weights/2023-10-28-18-33-37/
|
| 205 |
-
# weights/2024-01-11-20-02-45/
|
| 206 |
-
```
|
| 207 |
-
|
| 208 |
-
## Troubleshooting
|
| 209 |
-
|
| 210 |
-
### "Repository not found"
|
| 211 |
-
|
| 212 |
-
- Check repo name matches exactly: `YOUR_USERNAME/foundationpose-weights`
|
| 213 |
-
- Make sure repo is Public, or provide HF token for private repos
|
| 214 |
-
- Verify you're logged in: `huggingface-cli whoami`
|
| 215 |
-
|
| 216 |
-
### "Upload failed"
|
| 217 |
-
|
| 218 |
-
- Check your internet connection
|
| 219 |
-
- Try uploading smaller chunks
|
| 220 |
-
- Use CLI instead of web interface for large files
|
| 221 |
-
|
| 222 |
-
### "Out of storage"
|
| 223 |
-
|
| 224 |
-
- HF free tier has storage limits (~50GB)
|
| 225 |
-
- Request more storage or use smaller model variants
|
| 226 |
-
- Host on your own S3/CDN as alternative
|
| 227 |
-
|
| 228 |
-
### Private Repository Access
|
| 229 |
-
|
| 230 |
-
If your model repo is private, set HF token in Space secrets:
|
| 231 |
-
|
| 232 |
-
1. Get token from https://huggingface.co/settings/tokens
|
| 233 |
-
2. Add to Space: Settings → Repository secrets → `HF_TOKEN`
|
| 234 |
-
3. Code will automatically use it:
|
| 235 |
-
|
| 236 |
-
```python
|
| 237 |
-
from huggingface_hub import snapshot_download
|
| 238 |
-
import os
|
| 239 |
-
|
| 240 |
-
snapshot_download(
|
| 241 |
-
repo_id="YOUR_USERNAME/foundationpose-weights",
|
| 242 |
-
local_dir="./weights",
|
| 243 |
-
token=os.environ.get("HF_TOKEN") # Uses secret
|
| 244 |
-
)
|
| 245 |
-
```
|
| 246 |
-
|
| 247 |
-
## Example: Complete Workflow
|
| 248 |
-
|
| 249 |
-
```bash
|
| 250 |
-
# 1. Download from Google Drive (manual)
|
| 251 |
-
# Save to: ~/Downloads/foundationpose-weights/
|
| 252 |
-
|
| 253 |
-
# 2. Install HF CLI
|
| 254 |
-
pip install huggingface_hub
|
| 255 |
-
huggingface-cli login
|
| 256 |
-
|
| 257 |
-
# 3. Create model repo
|
| 258 |
-
huggingface-cli repo create foundationpose-weights --type model
|
| 259 |
-
|
| 260 |
-
# 4. Upload weights
|
| 261 |
-
cd ~/Downloads/foundationpose-weights
|
| 262 |
-
huggingface-cli upload gpue/foundationpose-weights . .
|
| 263 |
-
|
| 264 |
-
# 5. Update your Space
|
| 265 |
-
cd /path/to/foundationpose
|
| 266 |
-
git add .
|
| 267 |
-
git commit -m "Use HF model repo for weights"
|
| 268 |
-
git push
|
| 269 |
-
|
| 270 |
-
# 6. Set Space secrets
|
| 271 |
-
# Go to: https://huggingface.co/spaces/gpue/foundationpose/settings
|
| 272 |
-
# Add: FOUNDATIONPOSE_MODEL_REPO=gpue/foundationpose-weights
|
| 273 |
-
# Add: USE_HF_WEIGHTS=true
|
| 274 |
-
# Add: USE_REAL_MODEL=true
|
| 275 |
-
|
| 276 |
-
# 7. Check Space logs
|
| 277 |
-
# Visit: https://huggingface.co/spaces/gpue/foundationpose/logs
|
| 278 |
-
# Should see weights downloading automatically
|
| 279 |
-
```
|
| 280 |
-
|
| 281 |
-
## Alternative: Public Model Repos
|
| 282 |
-
|
| 283 |
-
If someone else has already uploaded the weights, you can use their repo:
|
| 284 |
-
|
| 285 |
-
```bash
|
| 286 |
-
# Example (if available)
|
| 287 |
-
export FOUNDATIONPOSE_MODEL_REPO="some-user/foundationpose-weights"
|
| 288 |
-
```
|
| 289 |
-
|
| 290 |
-
Common public repos (check if they exist):
|
| 291 |
-
- `nvidia/foundationpose` (official, if available)
|
| 292 |
-
- Community uploads (search on HF)
|
| 293 |
-
|
| 294 |
-
## Cost
|
| 295 |
-
|
| 296 |
-
✅ **Free tier:**
|
| 297 |
-
- Unlimited model repos
|
| 298 |
-
- ~50GB storage per repo
|
| 299 |
-
- Unlimited downloads (public repos)
|
| 300 |
-
- No bandwidth costs
|
| 301 |
-
|
| 302 |
-
📈 **Pro tier ($9/month):**
|
| 303 |
-
- More storage
|
| 304 |
-
- Private repos with teams
|
| 305 |
-
- Priority support
|
| 306 |
-
|
| 307 |
-
---
|
| 308 |
-
|
| 309 |
-
**Quick Reference:**
|
| 310 |
-
|
| 311 |
-
```bash
|
| 312 |
-
# Create repo
|
| 313 |
-
huggingface-cli repo create foundationpose-weights --type model
|
| 314 |
-
|
| 315 |
-
# Upload
|
| 316 |
-
huggingface-cli upload YOUR_USERNAME/foundationpose-weights ./weights .
|
| 317 |
-
|
| 318 |
-
# Download in Space (automatic)
|
| 319 |
-
python download_weights.py
|
| 320 |
-
|
| 321 |
-
# Or download manually
|
| 322 |
-
from huggingface_hub import snapshot_download
|
| 323 |
-
snapshot_download("YOUR_USERNAME/foundationpose-weights", local_dir="./weights")
|
| 324 |
-
```
|
| 325 |
-
|
| 326 |
-
---
|
| 327 |
-
|
| 328 |
-
You're all set! Your FoundationPose Space will now automatically download weights from your model repository on first run. 🎉
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import base64
|
|
| 8 |
import json
|
| 9 |
import logging
|
| 10 |
import os
|
|
|
|
| 11 |
from typing import Dict, List
|
| 12 |
|
| 13 |
import cv2
|
|
@@ -26,6 +27,49 @@ logger = logging.getLogger(__name__)
|
|
| 26 |
USE_REAL_MODEL = os.environ.get("USE_REAL_MODEL", "false").lower() == "true"
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
class FoundationPoseInference:
|
| 30 |
"""Wrapper for FoundationPose model inference."""
|
| 31 |
|
|
|
|
| 8 |
import json
|
| 9 |
import logging
|
| 10 |
import os
|
| 11 |
+
from pathlib import Path
|
| 12 |
from typing import Dict, List
|
| 13 |
|
| 14 |
import cv2
|
|
|
|
| 27 |
USE_REAL_MODEL = os.environ.get("USE_REAL_MODEL", "false").lower() == "true"
|
| 28 |
|
| 29 |
|
| 30 |
+
def download_weights_if_needed():
|
| 31 |
+
"""Download model weights from HuggingFace model repository if needed."""
|
| 32 |
+
weights_dir = Path("weights")
|
| 33 |
+
|
| 34 |
+
# Check if weights already exist
|
| 35 |
+
if weights_dir.exists() and any(weights_dir.glob("**/*.pth")):
|
| 36 |
+
logger.info("Model weights already exist locally")
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
# Only download if USE_REAL_MODEL is enabled
|
| 40 |
+
if not USE_REAL_MODEL:
|
| 41 |
+
logger.info("Placeholder mode - skipping weight download")
|
| 42 |
+
return False
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
from huggingface_hub import snapshot_download
|
| 46 |
+
|
| 47 |
+
model_repo = os.environ.get("FOUNDATIONPOSE_MODEL_REPO", "gpue/foundationpose-weights")
|
| 48 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 49 |
+
|
| 50 |
+
logger.info(f"Downloading model weights from {model_repo}...")
|
| 51 |
+
|
| 52 |
+
snapshot_download(
|
| 53 |
+
repo_id=model_repo,
|
| 54 |
+
local_dir=str(weights_dir),
|
| 55 |
+
token=hf_token,
|
| 56 |
+
repo_type="model"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
logger.info("✓ Model weights downloaded successfully")
|
| 60 |
+
return True
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
logger.error(f"Failed to download weights: {e}")
|
| 64 |
+
logger.warning("Falling back to placeholder mode")
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Download weights at startup if needed
|
| 69 |
+
logger.info("Checking model weights...")
|
| 70 |
+
download_weights_if_needed()
|
| 71 |
+
|
| 72 |
+
|
| 73 |
class FoundationPoseInference:
|
| 74 |
"""Wrapper for FoundationPose model inference."""
|
| 75 |
|