功能增加:新增后端传播任务执行器,支持异步自动传播、传播进度、结果统计、取消/重试状态同步。 功能增加:传播请求支持指定 SAM2.1 tiny/small/base+/large 权重,并记录 seed mask、source annotation 和传播范围。 功能增加:传播逻辑增加 seed 签名,未变化的 mask 二次传播会跳过,已变化的 mask 会先清理旧自动传播结果再重新生成,避免重复重叠。 功能增加:工作区增加传播范围二次选择、传播进度提示、人工/AI 标注帧红色标识、自动传播帧蓝色标识和当前帧双层边框。 功能增加:新增临时提示组件,让工具操作提示自动消失且不阻塞后续操作。 功能增加:补充项目删除、模板删除、任务失败详情、任务取消/重试等前后端联动状态。 功能增加:新增安装部署文档,补充当前需求冻结、设计冻结、接口契约、测试计划和 AGENTS/README 项目说明。 Bugfix:修复自动传播接口 404、传播后看不到任务进度、传播结果重复堆叠和已编辑帧提示不清晰的问题。 Bugfix:修复 AI 分割框选/点选交互、单候选 mask、删除选点、工作区保存与候选 mask 推送相关问题。 Bugfix:修复 Canvas 多边形顶点拖动告警、工具栏提示缺失、项目库 FPS 展示和若干 UI 文案/可用性问题。 测试:补充 AI 分割、Canvas、Dashboard、FrameTimeline、ProjectLibrary、TemplateRegistry、ToolsPalette、VideoWorkspace、API 和后端任务/AI/dashboard 测试。 验证:npm run lint;npm run test:run;python -m pytest backend/tests -q。
491 lines
9.6 KiB
Markdown
491 lines
9.6 KiB
Markdown
# Installation / 部署安装指南
|
||
|
||
本文件记录当前仓库的真实安装和部署方式。它面向一台新的 Linux 机器,目标是跑起完整系统:
|
||
|
||
- React 前端:默认 `http://localhost:3000`
|
||
- FastAPI 后端:默认 `http://localhost:8000`
|
||
- PostgreSQL:项目、帧、模板、标注、任务元数据
|
||
- Redis:Celery broker/result backend 与进度 pub/sub
|
||
- MinIO:视频、DICOM、拆帧图片等对象存储
|
||
- Celery worker:执行视频/DICOM 拆帧等后台任务
|
||
- SAM 2.1:当前产品启用 tiny/small/base+/large;SAM 3 源码保留但产品入口禁用,正常部署不需要安装 SAM 3
|
||
|
||
---
|
||
|
||
## 1. 前置条件
|
||
|
||
推荐环境:
|
||
|
||
| 项 | 建议 |
|
||
|----|------|
|
||
| OS | Ubuntu 22.04 LTS 或相近 Linux |
|
||
| Python | 3.11 |
|
||
| Node.js | 22.x |
|
||
| 数据库 | PostgreSQL 14+ |
|
||
| 缓存/队列 | Redis 6+ |
|
||
| 对象存储 | MinIO |
|
||
| 视频处理 | FFmpeg |
|
||
| GPU | NVIDIA GPU + CUDA,用于 SAM 2.1 推理;无 GPU 时可 CPU 运行但会很慢 |
|
||
|
||
安装系统依赖:
|
||
|
||
```bash
|
||
sudo apt update
|
||
sudo apt install -y \
|
||
postgresql postgresql-contrib \
|
||
redis-server \
|
||
ffmpeg \
|
||
libpq-dev build-essential curl ca-certificates gnupg wget
|
||
```
|
||
|
||
安装 MinIO:
|
||
|
||
```bash
|
||
cd /tmp
|
||
wget https://dl.min.io/server/minio/release/linux-amd64/minio
|
||
chmod +x minio
|
||
sudo mv minio /usr/local/bin/
|
||
mkdir -p ~/minio_data
|
||
```
|
||
|
||
---
|
||
|
||
## 2. 获取代码
|
||
|
||
```bash
|
||
cd ~/Desktop
|
||
git clone <your-gitea-or-git-url> Seg_Server
|
||
cd Seg_Server
|
||
```
|
||
|
||
如果已经有仓库,进入项目根目录即可:
|
||
|
||
```bash
|
||
cd /home/wkmgc/Desktop/Seg_Server
|
||
```
|
||
|
||
后续命令默认在项目根目录执行,除非特别说明。
|
||
|
||
---
|
||
|
||
## 3. 配置 PostgreSQL
|
||
|
||
默认后端配置来自 `backend/config.py`:
|
||
|
||
```text
|
||
postgresql://seguser:segpass123@localhost:5432/segserver
|
||
```
|
||
|
||
创建数据库和用户:
|
||
|
||
```bash
|
||
sudo systemctl start postgresql
|
||
|
||
sudo -u postgres psql -c "CREATE DATABASE segserver;"
|
||
sudo -u postgres psql -c "CREATE USER seguser WITH PASSWORD 'segpass123';"
|
||
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE segserver TO seguser;"
|
||
sudo -u postgres psql -d segserver -c "GRANT ALL ON SCHEMA public TO seguser;"
|
||
sudo -u postgres psql -c "ALTER DATABASE segserver OWNER TO seguser;"
|
||
```
|
||
|
||
验收:
|
||
|
||
```bash
|
||
pg_isready
|
||
psql "postgresql://seguser:segpass123@localhost:5432/segserver" -c "select 1;"
|
||
```
|
||
|
||
---
|
||
|
||
## 4. 启动 Redis 和 MinIO
|
||
|
||
Redis:
|
||
|
||
```bash
|
||
sudo systemctl start redis-server
|
||
redis-cli ping
|
||
```
|
||
|
||
MinIO:
|
||
|
||
```bash
|
||
nohup minio server ~/minio_data --console-address :9001 > /tmp/minio.log 2>&1 &
|
||
curl http://localhost:9000/minio/health/live
|
||
```
|
||
|
||
默认 MinIO 账号密码是:
|
||
|
||
```text
|
||
minioadmin / minioadmin
|
||
```
|
||
|
||
后端启动时会检查并创建 bucket:
|
||
|
||
```text
|
||
seg-media
|
||
```
|
||
|
||
---
|
||
|
||
## 5. 安装后端 Python 环境
|
||
|
||
推荐使用 Conda:
|
||
|
||
```bash
|
||
conda create -n seg_server python=3.11 -y
|
||
conda activate seg_server
|
||
```
|
||
|
||
安装 PyTorch。根据机器 CUDA 版本选择合适 wheel。示例:
|
||
|
||
```bash
|
||
# CUDA 12.4 示例
|
||
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
|
||
|
||
# 无 GPU / CPU 示例
|
||
# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
||
```
|
||
|
||
安装后端依赖:
|
||
|
||
```bash
|
||
cd backend
|
||
pip install -r requirements.txt
|
||
cd ..
|
||
```
|
||
|
||
确认关键包:
|
||
|
||
```bash
|
||
python - <<'PY'
|
||
import fastapi, sqlalchemy, redis, celery, minio, torch
|
||
print("torch:", torch.__version__, "cuda:", torch.cuda.is_available())
|
||
PY
|
||
```
|
||
|
||
---
|
||
|
||
## 6. 配置后端环境变量
|
||
|
||
后端从 `backend/.env` 读取配置;该文件被 `.gitignore` 忽略,不要提交真实密码或本机路径。
|
||
|
||
创建 `backend/.env`:
|
||
|
||
```bash
|
||
cat > backend/.env <<'EOF'
|
||
db_url=postgresql://seguser:segpass123@localhost:5432/segserver
|
||
redis_url=redis://localhost:6379/0
|
||
|
||
minio_endpoint=localhost:9000
|
||
minio_access_key=minioadmin
|
||
minio_secret_key=minioadmin
|
||
minio_secure=false
|
||
|
||
sam_default_model=sam2.1_hiera_tiny
|
||
sam_model_path=/home/wkmgc/Desktop/Seg_Server/models/sam2.1_hiera_tiny.pt
|
||
sam_model_config=configs/sam2.1/sam2.1_hiera_t.yaml
|
||
|
||
app_env=development
|
||
cors_origins=["http://localhost:3000","http://127.0.0.1:3000"]
|
||
EOF
|
||
```
|
||
|
||
如果前端通过局域网 IP 访问,例如 `http://192.168.3.11:3000`,需要把该地址加入 `cors_origins`,同时前端也要配置 API 地址。
|
||
|
||
---
|
||
|
||
## 7. 准备 SAM 2.1 权重
|
||
|
||
当前产品入口只暴露 SAM 2.1 变体:
|
||
|
||
- `sam2.1_hiera_tiny`
|
||
- `sam2.1_hiera_small`
|
||
- `sam2.1_hiera_base_plus`
|
||
- `sam2.1_hiera_large`
|
||
|
||
下载脚本:
|
||
|
||
```bash
|
||
cd backend
|
||
python download_sam2.py
|
||
cd ..
|
||
```
|
||
|
||
脚本默认下载到:
|
||
|
||
```text
|
||
/home/wkmgc/Desktop/Seg_Server/models/
|
||
```
|
||
|
||
推荐文件名:
|
||
|
||
```text
|
||
models/sam2.1_hiera_tiny.pt
|
||
models/sam2.1_hiera_small.pt
|
||
models/sam2.1_hiera_base_plus.pt
|
||
models/sam2.1_hiera_large.pt
|
||
```
|
||
|
||
可以只部署 tiny;前端会显示四个选项,但只有本地存在 checkpoint 的模型会显示可用。
|
||
|
||
注意:SAM 3 相关脚本和源码是历史保留。当前前端入口隐藏 SAM 3,后端 registry 不暴露 `sam3`,正常部署不需要下载 SAM 3 权重,也不要把 Hugging Face token 写进项目文件。
|
||
|
||
---
|
||
|
||
## 8. 安装前端依赖
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
如需指定前端访问的后端地址,在项目根目录创建 `.env`:
|
||
|
||
```bash
|
||
cat > .env <<'EOF'
|
||
VITE_API_BASE_URL=http://localhost:8000
|
||
VITE_WS_PROGRESS_URL=ws://localhost:8000/ws/progress
|
||
EOF
|
||
```
|
||
|
||
如果不设置,前端会按当前浏览器 hostname 推导:
|
||
|
||
```text
|
||
http://<browser-host>:8000
|
||
ws://<browser-host>:8000/ws/progress
|
||
```
|
||
|
||
---
|
||
|
||
## 9. 手动启动所有服务
|
||
|
||
开 4 个终端分别启动。
|
||
|
||
终端 A:FastAPI 后端
|
||
|
||
```bash
|
||
conda activate seg_server
|
||
cd /home/wkmgc/Desktop/Seg_Server/backend
|
||
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
||
```
|
||
|
||
终端 B:Celery worker
|
||
|
||
```bash
|
||
conda activate seg_server
|
||
cd /home/wkmgc/Desktop/Seg_Server/backend
|
||
celery -A celery_app:celery_app worker --loglevel=info --concurrency=1
|
||
```
|
||
|
||
终端 C:前端开发服务
|
||
|
||
```bash
|
||
cd /home/wkmgc/Desktop/Seg_Server
|
||
npm run dev
|
||
```
|
||
|
||
终端 D:确认基础设施
|
||
|
||
```bash
|
||
pg_isready
|
||
redis-cli ping
|
||
curl http://localhost:9000/minio/health/live
|
||
```
|
||
|
||
访问:
|
||
|
||
| 服务 | 地址 |
|
||
|------|------|
|
||
| 前端 | `http://localhost:3000` |
|
||
| FastAPI Docs | `http://localhost:8000/docs` |
|
||
| Health | `http://localhost:8000/health` |
|
||
| MinIO Console | `http://localhost:9001` |
|
||
|
||
默认开发登录:
|
||
|
||
```text
|
||
admin / 123456
|
||
```
|
||
|
||
---
|
||
|
||
## 10. 一键启动脚本
|
||
|
||
项目根目录有 `start_services.sh`:
|
||
|
||
```bash
|
||
chmod +x start_services.sh
|
||
./start_services.sh
|
||
```
|
||
|
||
脚本会检查/启动:
|
||
|
||
```text
|
||
PostgreSQL -> Redis -> MinIO -> FastAPI -> Celery worker -> 前端
|
||
```
|
||
|
||
使用前必须检查脚本里的本机路径和 sudo 逻辑:
|
||
|
||
- `PROJECT_DIR="/home/wkmgc/Desktop/Seg_Server"`
|
||
- `CONDA_ENV="seg_server"`
|
||
- MinIO 数据目录 `/home/wkmgc/minio_data`
|
||
- 脚本里包含本机 sudo 密码写法,迁移机器时应移除或改成安全的 systemd/service 管理方式
|
||
|
||
---
|
||
|
||
## 11. 生产构建方式
|
||
|
||
前端构建:
|
||
|
||
```bash
|
||
npm run build
|
||
```
|
||
|
||
生产模式启动前端静态服务:
|
||
|
||
```bash
|
||
NODE_ENV=production npm start
|
||
```
|
||
|
||
后端生产启动示例:
|
||
|
||
```bash
|
||
cd backend
|
||
uvicorn main:app --host 0.0.0.0 --port 8000
|
||
```
|
||
|
||
Celery worker 仍需要单独启动:
|
||
|
||
```bash
|
||
cd backend
|
||
celery -A celery_app:celery_app worker --loglevel=info --concurrency=1
|
||
```
|
||
|
||
实际生产建议用 systemd、supervisor 或容器编排托管 FastAPI、Celery、前端静态服务、MinIO、Redis、PostgreSQL。
|
||
|
||
---
|
||
|
||
## 12. 部署验收 Checklist
|
||
|
||
基础服务:
|
||
|
||
```bash
|
||
pg_isready
|
||
redis-cli ping
|
||
curl http://localhost:9000/minio/health/live
|
||
curl http://localhost:8000/health
|
||
```
|
||
|
||
后端模型状态:
|
||
|
||
```bash
|
||
curl http://localhost:8000/api/ai/models/status
|
||
```
|
||
|
||
前端质量检查:
|
||
|
||
```bash
|
||
npm run lint
|
||
npm run test:run
|
||
npm run build
|
||
```
|
||
|
||
后端测试:
|
||
|
||
```bash
|
||
conda activate seg_server
|
||
python -m pytest backend/tests
|
||
```
|
||
|
||
手工业务验收:
|
||
|
||
1. 打开 `http://localhost:3000`。
|
||
2. 使用 `admin / 123456` 登录。
|
||
3. 创建项目或上传视频。
|
||
4. 在项目库点击“生成帧”,选择 FPS。
|
||
5. Dashboard 中应看到任务进度;Celery 日志应显示拆帧任务。
|
||
6. 进入分割工作区,能看到帧、时间轴和画布。
|
||
7. 手工画一个多边形 mask,点击“结构化归档保存”。
|
||
8. 刷新工作区后,已保存标注应回显。
|
||
9. AI 智能分割中选择可用 SAM 2.1 模型,放置点或框,执行分割。
|
||
10. 导出 JSON 或 PNG Mask ZIP。
|
||
|
||
---
|
||
|
||
## 13. 常见问题
|
||
|
||
### 前端打不开或请求后端失败
|
||
|
||
检查:
|
||
|
||
```bash
|
||
curl http://localhost:8000/health
|
||
cat .env
|
||
```
|
||
|
||
如果通过局域网 IP 访问前端,确保:
|
||
|
||
- `.env` 中 `VITE_API_BASE_URL` 是浏览器可访问的后端地址。
|
||
- `backend/.env` 中 `cors_origins` 包含前端地址。
|
||
|
||
### Dashboard WebSocket 经常断开
|
||
|
||
检查:
|
||
|
||
```bash
|
||
redis-cli ping
|
||
curl http://localhost:8000/health
|
||
```
|
||
|
||
同时确认前端 `VITE_WS_PROGRESS_URL` 指向真实可访问的:
|
||
|
||
```text
|
||
ws://<host>:8000/ws/progress
|
||
```
|
||
|
||
### 生成帧没有进度
|
||
|
||
检查 Celery worker 是否启动:
|
||
|
||
```bash
|
||
ps aux | grep celery
|
||
tail -f /tmp/celery.log
|
||
```
|
||
|
||
检查 Redis:
|
||
|
||
```bash
|
||
redis-cli ping
|
||
```
|
||
|
||
### MinIO 上传失败
|
||
|
||
检查:
|
||
|
||
```bash
|
||
curl http://localhost:9000/minio/health/live
|
||
tail -f /tmp/minio.log
|
||
```
|
||
|
||
如果磁盘空间不足,MinIO 可能拒绝写入。清理 `~/minio_data`、旧日志、旧模型权重或迁移数据目录。
|
||
|
||
### SAM 2 模型不可用
|
||
|
||
检查:
|
||
|
||
```bash
|
||
ls -lh models/
|
||
curl http://localhost:8000/api/ai/models/status
|
||
```
|
||
|
||
常见原因:
|
||
|
||
- checkpoint 文件不存在。
|
||
- `backend/.env` 中 `sam_model_path` 指向旧文件名。
|
||
- `sam2` Python 包未正确安装。
|
||
- PyTorch/CUDA 不匹配。
|
||
|
||
### 不需要 SAM 3
|
||
|
||
当前版本不用 SAM 3。不要为了正常部署执行 `backend/setup_sam3_env.sh`,也不要在项目里保存 Hugging Face token。
|
||
|