Skip to content

Conversation

@undertaker86001
Copy link

@undertaker86001 undertaker86001 commented Sep 3, 2025

【ML backend】振动样本多标签预测

概述

基于toklabel框架,为工业互联网PHM(预测性维护)公司提供振动数据AI自动化打标解决方案。系统实现了多标签标注功能,包括转速段标注、故障类型检测、质量分数评估和置信度处理。

核心功能

1. 多标签标注

  • 转速标注: 创建多个TimeseriesSpan对象,分别标注低、中、高转速段
  • 质量标注: 使用Number类型标注质量分数(0-100)
  • 故障检测: 识别不平衡、轴承故障、齿轮故障等
  • 置信度处理: 每个预测结果包含置信度信息

2. 振动特征提取

  • 时域特征: RMS值、峰值、标准差、峰度、偏度、峰值因子
  • 频域特征: 主频、频谱质心、频谱滚降、频谱带宽
  • 转速特征: 平均转速、转速稳定性、转速变化范围

3. 智能预测

  • 转速段预测: 基于滑动窗口的转速等级识别
  • 故障诊断: 基于振动特征的故障类型判断
  • 质量评估: 多维度综合评分算法
  • 在线学习: 支持标注数据反馈训练(基于IsolationForest)

系统架构

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Label Studio  │    │   ML Backend    │    │   Data Manager  │
│   (标注界面)     │◄──►│   (AI预测)      │◄──►│   (数据管理)     │
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                       │                       │
         ▼                       ▼                       ▼
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   PostgreSQL    │    │     Redis       │    │   File Server   │
│   (标注存储)     │    │   (缓存)        │    │   (文件服务)     │
└─────────────────┘    └─────────────────┘    └─────────────────┘

快速开始

1. 环境准备

# 安装依赖
pip install -r ml-backends/vibration_phm/requirements.txt

# 启动PostgreSQL和Redis
docker-compose up -d postgres redis

# 启动Label Studio
label-studio start

2. 数据库初始化

# 创建数据库表结构
python scripts/init_vibration_database.py

# 插入示例数据
python scripts/init_vibration_database.py

3. 启动ML后端

# 使用Docker Compose启动
cd ml-backends/vibration_phm
docker-compose up -d

# 或直接启动
python ml-backends/vibration_phm/_wsgi.py

4. 创建标注项目

# 修改配置参数
vim vibration_project_create.py

# 运行项目创建脚本
python vibration_project_create.py

5. 系统启动

# 一键启动整个系统
python scripts/start_vibration_system.py

配置说明

项目配置文件 (vibration-config.yaml)

# 项目基本信息
project: vibration_phm
project_description: '工业设备振动数据预测性维护标注项目'
project_data_type: 'Timeseries'

# 数据配置
shots:
  min: 240829001
  max: 240829100
t_min: 0
t_max: 60
resolution: 0.001

# 振动传感器数据
raw_data:
  vibration_x:
    data_table_name: vibration_sensors
    channels: [x_axis]
  vibration_y:
    data_table_name: vibration_sensors
    channels: [y_axis]
  vibration_z:
    data_table_name: vibration_sensors
    channels: [z_axis]
  rotation_speed:
    data_table_name: rotation_sensors
    channels: [rpm]

# 标签配置
label_config:
  - name: speed_level
    type: TimeSeriesLabels
    choices: [低转速, 中转速, 高转速]
  - name: fault_type
    type: TimeSeriesLabels
    choices: [正常, 不平衡, 轴承故障, 齿轮故障]
  - name: quality_score
    type: Number
    min: 0
    max: 100
  - name: confidence_level
    type: Number
    min: 0
    max: 1

核心组件

1. 振动预测器 (VibrationPredictor)

from ml_backends.vibration_phm.predictor import VibrationPredictor

# 创建预测器
predictor = VibrationPredictor()

# 执行预测
predictions = predictor.predict(vibration_data)

主要功能:

  • 提取时域和频域特征
  • 转速段自动分割
  • 故障类型识别
  • 质量分数计算

2. 数据管理器 (VibrationDataManager)

from vibration_data_manager import VibrationDataManager

# 创建数据管理器
manager = VibrationDataManager(postgres_config, redis_config)

# 导出振动数据
urls = manager.export_vibration_data(shots, t_min=0, t_max=60)

# 查询标注数据
annotations = manager.query_annotations_by_conditions(shot_ids=shots)

主要功能:

  • 振动数据导出
  • 标注数据存储
  • 条件查询
  • 训练数据生成

3. 标注分析器 (VibrationAnnotationAnalyzer)

from scripts.annotation_analysis import VibrationAnnotationAnalyzer

# 创建分析器
analyzer = VibrationAnnotationAnalyzer(postgres_config, redis_config)

# 生成标注报告
report = analyzer.export_annotation_report(shots, 'report.json')

# 生成可视化图表
analyzer.generate_comprehensive_charts(shots, 'charts/')

主要功能:

  • 标注统计报告
  • 质量趋势分析
  • 故障分布可视化
  • 置信度分析

API接口

ML后端API

# 健康检查
GET http://localhost:9090/health

# 预测接口
POST http://localhost:9090/predict
Content-Type: application/json

{
  "tasks": [
    {
      "data": {
        "shot": 240829001,
        "csv": "http://file-server:8000/data/vibration_data_240829001.csv"
      }
    }
  ]
}

响应格式

{
  "predictions": [
    {
      "result": [
        {
          "from_name": "speed_level",
          "to_name": "ts",
          "type": "timeserieslabels",
          "value": {
            "start": 0.0,
            "end": 30.0,
            "timeserieslabels": ["中转速"]
          },
          "score": 0.85
        },
        {
          "from_name": "quality_score",
          "to_name": "ts",
          "type": "number",
          "value": {
            "number": 85.6
          },
          "score": 0.8
        }
      ],
      "score": 0.825
    }
  ]
}

部署指南

Docker部署

# 构建镜像
cd ml-backends/vibration_phm
docker build -t vibration-phm:latest .

# 启动服务
docker-compose up -d

Kubernetes部署

# 应用部署配置
kubectl apply -f k8s/vibration-phm-deployment.yaml

# 检查服务状态
kubectl get pods -n label-studio
kubectl logs -f vibration-phm-ml-backend-xxx

开发指南

添加新的预测特征

class VibrationPredictor(BasePredictor):
    def extract_features(self, data: pd.DataFrame) -> Dict:
        features = super().extract_features(data)
        
        # 添加新特征
        features['new_feature'] = self._calculate_new_feature(data)
        
        return features
    
    def _calculate_new_feature(self, data: pd.DataFrame) -> float:
        # 实现新特征计算逻辑
        return calculated_value

扩展故障类型

def predict_fault_type(self, data: pd.DataFrame, features: Dict) -> List[TimeseriesSpan]:
    # 添加新的故障检测逻辑
    if features.get('new_indicator', 0) > threshold:
        return [TimeseriesSpan(
            start=time[0],
            end=time[-1],
            label_choice='新故障类型',
            label_group="fault_type"
        )]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants