2025-08-02 12:38:52 +08:00
|
|
|
|
from sqlalchemy import Column, String, Text, Boolean, Float, Integer
|
|
|
|
|
from .base import BaseModel
|
2025-08-05 11:57:14 +08:00
|
|
|
|
import json
|
2025-08-02 12:38:52 +08:00
|
|
|
|
|
|
|
|
|
class Algorithm(BaseModel):
|
|
|
|
|
__tablename__ = "algorithms"
|
|
|
|
|
|
|
|
|
|
name = Column(String(100), nullable=False, comment="算法名称")
|
|
|
|
|
description = Column(Text, comment="算法描述")
|
|
|
|
|
version = Column(String(20), nullable=False, comment="算法版本")
|
|
|
|
|
model_path = Column(String(255), comment="模型文件路径")
|
|
|
|
|
config_path = Column(String(255), comment="配置文件路径")
|
|
|
|
|
status = Column(String(20), default="inactive", comment="算法状态: active, inactive, training")
|
|
|
|
|
accuracy = Column(Float, comment="算法准确率")
|
|
|
|
|
detection_classes = Column(Text, comment="检测类别,JSON格式")
|
|
|
|
|
input_size = Column(String(20), comment="输入尺寸,如: 640x640")
|
|
|
|
|
inference_time = Column(Float, comment="推理时间(ms)")
|
|
|
|
|
is_enabled = Column(Boolean, default=True, comment="是否启用")
|
|
|
|
|
creator = Column(String(50), comment="创建者")
|
2025-08-05 11:57:14 +08:00
|
|
|
|
tags = Column(Text, comment="标签,JSON格式")
|
|
|
|
|
|
|
|
|
|
def to_dict(self) -> dict:
|
|
|
|
|
"""将模型实例转换为字典格式"""
|
|
|
|
|
return {
|
|
|
|
|
"id": self.id,
|
|
|
|
|
"name": self.name,
|
|
|
|
|
"description": self.description,
|
|
|
|
|
"version": self.version,
|
|
|
|
|
"model_path": self.model_path,
|
|
|
|
|
"config_path": self.config_path,
|
|
|
|
|
"status": self.status,
|
|
|
|
|
"accuracy": self.accuracy,
|
|
|
|
|
"detection_classes": self.detection_classes,
|
|
|
|
|
"input_size": self.input_size,
|
|
|
|
|
"inference_time": self.inference_time,
|
|
|
|
|
"is_enabled": self.is_enabled,
|
|
|
|
|
"creator": self.creator,
|
|
|
|
|
"tags": self.tags,
|
|
|
|
|
"created_at": self.created_at,
|
|
|
|
|
"updated_at": self.updated_at
|
|
|
|
|
}
|