深度估计Docker服务

深度估计Docker服务是一个基于Apple Depth Pro模型的Docker容器化部署解决方案,提供零样本单目度量深度估计功能,适用于室内和近距离户外场景。

  • by neosun100
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 neosun100/depth-pro-docker

使用说明

英语 | 简体中文 | 繁体中文 | 日本语

🔬 深度专业Docker

针对苹果Depth Pro模型的生产就绪Docker部署

零样本单眼测量深度估计•2.25MP深度图,0.3s


✨ 特性

特性 描述
🚀 一键部署 Docker Compose实现即时部署
🎨 现代Web用户界面 具有多种颜色映射的漂亮界面
🔌 REST API 带Swagger文档的全配方API
🤖 MCP服务器 AI助手的模型上下文协议支持
📊 多个输出 JPG可视化,NPZ数据,16位PNG
🎛️ 手动焦距 覆盖自动焦距估计
🌐 多语言 中文、英文、日文用户界面
💾 GPU管理 自动内存卸载、状态监控

🚀 快速开始

# One command to run (All-in-One image, no downloads needed!)
docker run -d --name depth-pro --gpus all -p 8500:8500 neosun/depth-pro:latest

# Open browser
open http://localhost:8500

📦 安装

先决条件

  • Docker 24.0+与NVIDIA容器工具包
  • 配备8GB+VRAM的NVIDIA GPU(推荐16GB+)
  • CUDA 12.1兼容驱动程序

方法一:Docker运行(推荐)

All-in-One图像包括模型重量(~5GB),无需额外下载!

# Pull and run (model included in image)
docker run -d \
  --name depth-pro \
  --gpus all \
  -p 8500:8500 \
  -e GPU_IDLE_TIMEOUT=60 \
  neosun/depth-pro:latest

方法二:Docker编写

# Create docker-compose.yml
cat > docker-compose.yml << 'EOF'
services:
  depth-pro:
    image: neosun/depth-pro:latest
    container_name: depth-pro
    ports:
      - "8500:8500"
    environment:
      - GPU_IDLE_TIMEOUT=60
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped
EOF

# Start service
docker compose up -d

方法3:地方发展

# Create conda environment
conda create -n depth-pro python=3.9 -y
conda activate depth-pro

# Install dependencies
pip install -e .
pip install flask flask-cors flasgger gunicorn

# Download model
source get_pretrained_models.sh

# Run server
python app.py

⚙️ 配置

环境变量

变量 默认值 描述
PORT 8500 服务器端口
GPU_IDLE_TIMEOUT 60 GPU内存释放前几秒
NVIDIA_VISIBLE_DEVICES 0 GPU设备索引

docker-compose.yml

services:
  depth-pro:
    image: neosun/depth-pro:latest
    container_name: depth-pro
    ports:
      - "8500:8500"
    environment:
      - PORT=8500
      - GPU_IDLE_TIMEOUT=60
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8500/health"]
      interval: 30s
      timeout: 10s
      retries: 3

📖 用法

网络界面

访问 http://localhost:8500 对于交互式UI:

  1. 上传图片(JPG/PNG/WebP/HEIC)
  2. 选择配色图(Turbo、Viridis、Plasma等)
  3. 可选择设置手动焦距
  4. 点击“流程”并下载结果

REST API

深度估计

curl -X POST http://localhost:8500/api/predict \
  -F "file=@image.jpg" \
  -F "colormap=turbo" \
  -F "focal_length=1000"

答复:

{
  "task_id": "abc12345",
  "focal_length_px": 1000.0,
  "min_depth_m": 0.5,
  "max_depth_m": 10.2,
  "mean_depth_m": 3.4,
  "image_size": "1920x1080",
  "depth_image_base64": "...",
  "download_jpg": "/api/download/abc12345/color.jpg",
  "download_npz": "/api/download/abc12345/depth.npz",
  "download_16bit": "/api/download/abc12345/depth16.png"
}

GPU状态

curl http://localhost:8500/api/gpu/status

释放GPU内存

curl -X POST http://localhost:8500/api/gpu/offload

API 文档

Swagger用户界面可在以下网址获得: http://localhost:8500/apidocs/

MCP服务器(用于AI助手)

添加到您的Claude Desktop配置中:

{
  "mcpServers": {
    "depth-pro": {
      "command": "docker",
      "args": ["exec", "-i", "depth-pro", "python3", "mcp_server.py"]
    }
  }
}

可用的MCP工具:

  • estimate_depth -处理单张图像
  • batch_estimate_depth -处理多个图像
  • get_gpu_status -检查GPU状态
  • release_gpu -免费GPU内存

📁 项目结构

depth-pro-docker/
├── app.py                 # Flask web server
├── mcp_server.py          # MCP server for AI assistants
├── gpu_manager.py         # GPU memory management
├── Dockerfile             # Container build file
├── docker-compose.yml     # Docker Compose config
├── checkpoints/           # Model weights (download separately)
│   └── depth_pro.pt
├── src/depth_pro/         # Core model code
├── templates/             # HTML templates
├── static/                # CSS/JS assets
└── docs/                  # Documentation

🛠️ 技术栈

  • 模型:苹果深度专业版(DINOv2+多尺度ViT)
  • 后端:Flask+Gunicorn
  • 前端:香草JS+现代CSS
  • 容器:Docker+NVIDIA容器工具包
  • 图形处理器:PyTorch+CUDA 12.1

📝 局限性

  • 远场场景(>20m)的绝对深度值可能不准确
  • 最适合室内和近距离室外场景
  • 即使对于远场景,相对深度排序通常也是可靠的

🤝 贡献

欢迎投稿!请阅读 贡献.md 第一。

  1. 分叉存储库
  2. 创建特征分支(git checkout -b feature/amazing)
  3. 提交更改(git commit -m 'Add amazing feature')
  4. 推送到分支(git push origin feature/amazing)
  5. 打开拉取请求

📄 许可证

本项目基于 苹果深度Pro 并根据 苹果示例代码许可证.

🙏 致谢


⭐ 明星历史

📱 跟我来