diff --git a/app/api/business/project_detect_api.py b/app/api/business/project_detect_api.py index 8cf3b6e..9bb9348 100644 --- a/app/api/business/project_detect_api.py +++ b/app/api/business/project_detect_api.py @@ -119,7 +119,7 @@ def run_detect_yolo(detect_log_in: ProjectDetectLogIn, session: Session = Depend return rc.response_error("训练权重不存在") detect_img_count = pdc.check_detect_img(detect_log_in.detect_id, session) if detect_img_count == 0: - return rc.response_error("推理集合中没有图片,请先到推理集合中上传图片") + return rc.response_error("推理集合中没有内容,请先到推理集合中上传图片") detect_log = pds.run_detect_yolo(detect_log_in, detect, train, session) thread_train = threading.Thread(target=run_event_loop, args=(detect_log.pt_url, detect_log.folder_url, diff --git a/app/model/bussiness_model.py b/app/model/bussiness_model.py index ec90be1..e1024cf 100644 --- a/app/model/bussiness_model.py +++ b/app/model/bussiness_model.py @@ -82,6 +82,7 @@ class ProjectTrain(DbCommon): project_id: Mapped[int] = mapped_column(Integer, nullable=False) train_version: Mapped[str] = mapped_column(String(32), nullable=False) train_url: Mapped[str] = mapped_column(String(255), nullable=False) + train_data: Mapped[str] = mapped_column(String(255), nullable=False) weights_id: Mapped[int] = mapped_column(Integer) weights_name: Mapped[str] = mapped_column(String(32)) epochs: Mapped[int] = mapped_column(Integer) diff --git a/app/model/schemas/project_train_schemas.py b/app/model/schemas/project_train_schemas.py index 7cf9678..75f072e 100644 --- a/app/model/schemas/project_train_schemas.py +++ b/app/model/schemas/project_train_schemas.py @@ -5,7 +5,7 @@ from typing import Optional class ProjectTrainIn(BaseModel): project_id: Optional[int] = Field(..., description="项目id") - weights_id: Optional[int] = Field(None, description="权重文件") + weights_id: Optional[str] = Field(None, description="权重文件") epochs: Optional[int] = Field(50, description="训练轮数") patience: Optional[int] = Field(20, description="早停的耐心值") diff --git a/app/service/project_detect_service.py b/app/service/project_detect_service.py index 6177263..cfdcac7 100644 --- a/app/service/project_detect_service.py +++ b/app/service/project_detect_service.py @@ -172,7 +172,8 @@ async def run_commend(weights: str, source: str, project: str, name: str, pdc.add_detect_imgs(detect_log_imgs, session) - +def run_detect_rtsp(): + return None diff --git a/app/service/project_train_service.py b/app/service/project_train_service.py index 61d8366..07c4b11 100644 --- a/app/service/project_train_service.py +++ b/app/service/project_train_service.py @@ -176,10 +176,7 @@ def run_train_yolo(project_info: ProjectInfoOut, train_in: ProjectTrainIn, sessi data = yaml_file project = os.file_path(runs_url, project_info.project_no) name = version_path - # thread_train = threading.Thread(target=ps.run_commend, args=(data, project, name, train_in.epochs, - # train_in.patience, train_in.weights_id, - # train_in.project_id, session,)) - # thread_train.start(); + return data, project, name @@ -203,9 +200,9 @@ async def run_commend(data: str, project: str, await room_manager.send_to_room(room, f"stdout: 模型训练开始,请稍等。。。\n") commend = ["python", '-u', yolo_path, "--data=" + data, "--project=" + project, "--name=" + name, "--epochs=" + str(epochs), "--batch-size=4", "--exist-ok", "--patience=" + str(patience)] - if weights != None and weights != '': - train_info = ptc.get_train(weights, session) - if train_info != None: + if weights != '' and weights is not None: + train_info = ptc.get_train(int(weights), session) + if train_info is not None: commend.append("--weights=" + train_info.best_pt) # 启动子进程 with subprocess.Popen( @@ -236,6 +233,7 @@ async def run_commend(data: str, project: str, train.train_version = name train_url = os.file_path(project, name) train.train_url = train_url + train.train_data = data bast_pt_path = os.file_path(train_url, 'weights', 'best.pt') last_pt_path = os.file_path(train_url, 'weights', 'last.pt') train.best_pt = bast_pt_path diff --git a/app/util/csv_utils.py b/app/util/csv_utils.py index a336e98..e557e85 100644 --- a/app/util/csv_utils.py +++ b/app/util/csv_utils.py @@ -14,6 +14,8 @@ def read_csv(file_path): next(csv_reader) result_row = [] for row in csv_reader: + if row is None: + break result_row.append(row) return result_row return None diff --git a/app/util/ps_util.py b/app/util/ps_util.py index 3f296c2..1cd80fa 100644 --- a/app/util/ps_util.py +++ b/app/util/ps_util.py @@ -10,29 +10,29 @@ def get_server_info(): # 1. 系统基本信息 info["system"] = { - "OS": platform.system(), - "OS版本": platform.version(), - "主机名": platform.node(), - "架构": platform.machine(), - "处理器型号": platform.processor(), - "启动时间": datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S") + "os": platform.system(), + "os_version": platform.version(), + "node": platform.node(), + "machine": platform.machine(), + "processor": platform.processor(),# 处理器型号 + "boot_time": datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S") # 启动时间 } # 2. CPU 信息 cpu_usage = psutil.cpu_percent(interval=1) info["cpu"] = { - "物理核心数": psutil.cpu_count(logical=False), - "逻辑核心数": psutil.cpu_count(logical=True), - "当前使用率 (%)": cpu_usage, - "每个核心使用率": psutil.cpu_percent(interval=1, percpu=True) + "cpu_count": psutil.cpu_count(logical=False), + "cpu_count_logical": psutil.cpu_count(logical=True), + "cpu_usage": cpu_usage, + "cpu_percent": psutil.cpu_percent(interval=1, percpu=True) } # 3. 内存信息 mem = psutil.virtual_memory() info["memory"] = { - "总内存 (GB)": round(mem.total / (1024**3), 2), - "可用内存 (GB)": round(mem.available / (1024**3), 2), - "使用率 (%)": mem.percent + "total": round(mem.total / (1024**3), 2), + "available": round(mem.available / (1024**3), 2), + "percent": mem.percent } # 4. 磁盘信息 @@ -40,20 +40,20 @@ def get_server_info(): for partition in psutil.disk_partitions(): usage = psutil.disk_usage(partition.mountpoint) disks.append({ - "设备": partition.device, - "挂载点": partition.mountpoint, - "文件系统": partition.fstype, - "总空间 (GB)": round(usage.total / (1024**3), 2), - "已用空间 (GB)": round(usage.used / (1024**3), 2), - "使用率 (%)": usage.percent + "device": partition.device, + "mountpoint": partition.mountpoint, + "fstype": partition.fstype, + "total": round(usage.total / (1024**3), 2), + "used": round(usage.used / (1024**3), 2), + "percent": usage.percent }) info["disks"] = disks # 5. 网络信息 net = psutil.net_io_counters() info["network"] = { - "发送流量 (MB)": round(net.bytes_sent / (1024**2), 2), - "接收流量 (MB)": round(net.bytes_recv / (1024**2), 2) + "bytes_sent": round(net.bytes_sent / (1024**2), 2), + "bytes_recv": round(net.bytes_recv / (1024**2), 2) } # 6. 进程信息(示例:前5个高CPU进程) @@ -64,10 +64,10 @@ def get_server_info(): if proc.info['cpu_percent'] > 0: processes.append({ "PID": proc.info['pid'], - "进程名": proc.info['name'], - "CPU使用率 (%)": proc.info['cpu_percent'] + "name": proc.info['name'], + "cpu_percent": proc.info['cpu_percent'] }) - info["top_processes"] = sorted(processes, key=lambda x: x["CPU使用率 (%)"], reverse=True) + info["top_processes"] = sorted(processes, key=lambda x: x["cpu_percent"], reverse=True) return info