Files
SkyLi 356a308f9b Initial commit: Infrared Equipment Fault Detection HTTP Service
- Add FastAPI microservice for infrared equipment fault detection
- Add dual pyproject.toml: local development and Docker deployment
- Add MANUAL_SETUP.md for manual file placement instructions
- Add Dockerfile for containerized deployment
- Add sample .env.example for PROJECT_ROOT configuration
- Configure gitignore for weights, lib, venv, and environment files
2026-03-28 20:28:32 +08:00

2.9 KiB

Infrared Equipment Fault Detection Service

红外设备故障检测 HTTP 微服务,基于 infrared-data whl 包提供推理接口。

功能特性

  • RESTful API 服务
  • 支持红外图像故障诊断
  • 返回检测框、温度特征、故障状态
  • CPU/GPU 灵活切换

项目结构

.
├── lib/                          # whl 包(需手动放置)
│   └── infrared_data-0.1.0-py3-none-any.whl
├── weights/                      # 模型权重(需手动放置)
│   └── best.pt
├── src/
│   ├── __init__.py
│   ├── config.py                 # 配置
│   └── main.py                   # FastAPI 应用
├── tests/
│   └── valid/                    # 测试图片和结果
├── pyproject.toml                # 本地依赖配置
├── pyproject.docker.toml         # Docker 依赖配置
├── Dockerfile                    # Docker 镜像
├── MANUAL_SETUP.md               # 手动部署说明
└── README.md                     # 本文件

快速开始

1. 手动放置文件

在部署前,需要手动获取并放置以下文件:

文件 存放路径
whl 包 lib/infrared_data-0.1.0-py3-none-any.whl
模型权重 weights/best.pt

详细说明请参考 MANUAL_SETUP.md。

2. 安装依赖

uv sync

3. 启动服务

# CPU 模式
INFERENCE_DEVICE=cpu uv run uvicorn src.main:app --host 0.0.0.0 --port 8000

# GPU 模式
INFERENCE_DEVICE=cuda:0 uv run uvicorn src.main:app --host 0.0.0.0 --port 8000

4. 测试

# 健康检查
curl http://localhost:8000/health

# 推理测试
curl -X POST http://localhost:8000/infer -F "image=@your_image.jpg"

API 文档

启动服务后访问: http://localhost:8000/docs

POST /infer

上传红外图像进行故障诊断。

请求

  • Content-Type: multipart/form-data
  • 字段: image (图片文件)

响应

{
  "image": "array",
  "detections": [
    {
      "bbox": [x1, y1, x2, y2],
      "bbox_xywh": [cx, cy, w, h],
      "confidence": 0.94,
      "class_id": 4,
      "class_name": "conservator"
    }
  ],
  "faults": [
    {
      "temp_max": 255.0,
      "temp_min": 0.0,
      "temp_mean": 81.1,
      "temp_std": 68.3,
      "temp_median": 57.0,
      "fault_status": "abnormal",
      "fault_type": "hotspot"
    }
  ],
  "summary": {
    "status": "fault_detected",
    "detection_count": 3,
    "abnormal_count": 3,
    "fault_types": ["hotspot"]
  }
}

GET /health

健康检查接口。

响应

{
  "status": "ok",
  "device": "cpu"
}

Docker 部署

# 构建镜像
docker build -t infrared-inference .

# 运行容器
docker run -p 8000:8000 infrared-inference

故障类型

类型 说明
none 正常
hotspot 热点异常
local_overheating 局部过热
overheat 过热
suspect 可疑