细化部分功能

This commit is contained in:
2025-03-13 17:35:03 +08:00
parent 76f4a5ecd9
commit 6daea23f0a
7 changed files with 36 additions and 34 deletions

View File

@ -119,7 +119,7 @@ def run_detect_yolo(detect_log_in: ProjectDetectLogIn, session: Session = Depend
return rc.response_error("训练权重不存在") return rc.response_error("训练权重不存在")
detect_img_count = pdc.check_detect_img(detect_log_in.detect_id, session) detect_img_count = pdc.check_detect_img(detect_log_in.detect_id, session)
if detect_img_count == 0: 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) 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, thread_train = threading.Thread(target=run_event_loop, args=(detect_log.pt_url,
detect_log.folder_url, detect_log.folder_url,

View File

@ -82,6 +82,7 @@ class ProjectTrain(DbCommon):
project_id: Mapped[int] = mapped_column(Integer, nullable=False) project_id: Mapped[int] = mapped_column(Integer, nullable=False)
train_version: Mapped[str] = mapped_column(String(32), nullable=False) train_version: Mapped[str] = mapped_column(String(32), nullable=False)
train_url: Mapped[str] = mapped_column(String(255), 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_id: Mapped[int] = mapped_column(Integer)
weights_name: Mapped[str] = mapped_column(String(32)) weights_name: Mapped[str] = mapped_column(String(32))
epochs: Mapped[int] = mapped_column(Integer) epochs: Mapped[int] = mapped_column(Integer)

View File

@ -5,7 +5,7 @@ from typing import Optional
class ProjectTrainIn(BaseModel): class ProjectTrainIn(BaseModel):
project_id: Optional[int] = Field(..., description="项目id") 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="训练轮数") epochs: Optional[int] = Field(50, description="训练轮数")
patience: Optional[int] = Field(20, description="早停的耐心值") patience: Optional[int] = Field(20, description="早停的耐心值")

View File

@ -172,7 +172,8 @@ async def run_commend(weights: str, source: str, project: str, name: str,
pdc.add_detect_imgs(detect_log_imgs, session) pdc.add_detect_imgs(detect_log_imgs, session)
def run_detect_rtsp():
return None

View File

@ -176,10 +176,7 @@ def run_train_yolo(project_info: ProjectInfoOut, train_in: ProjectTrainIn, sessi
data = yaml_file data = yaml_file
project = os.file_path(runs_url, project_info.project_no) project = os.file_path(runs_url, project_info.project_no)
name = version_path 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 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") await room_manager.send_to_room(room, f"stdout: 模型训练开始,请稍等。。。\n")
commend = ["python", '-u', yolo_path, "--data=" + data, "--project=" + project, "--name=" + name, commend = ["python", '-u', yolo_path, "--data=" + data, "--project=" + project, "--name=" + name,
"--epochs=" + str(epochs), "--batch-size=4", "--exist-ok", "--patience=" + str(patience)] "--epochs=" + str(epochs), "--batch-size=4", "--exist-ok", "--patience=" + str(patience)]
if weights != None and weights != '': if weights != '' and weights is not None:
train_info = ptc.get_train(weights, session) train_info = ptc.get_train(int(weights), session)
if train_info != None: if train_info is not None:
commend.append("--weights=" + train_info.best_pt) commend.append("--weights=" + train_info.best_pt)
# 启动子进程 # 启动子进程
with subprocess.Popen( with subprocess.Popen(
@ -236,6 +233,7 @@ async def run_commend(data: str, project: str,
train.train_version = name train.train_version = name
train_url = os.file_path(project, name) train_url = os.file_path(project, name)
train.train_url = train_url train.train_url = train_url
train.train_data = data
bast_pt_path = os.file_path(train_url, 'weights', 'best.pt') bast_pt_path = os.file_path(train_url, 'weights', 'best.pt')
last_pt_path = os.file_path(train_url, 'weights', 'last.pt') last_pt_path = os.file_path(train_url, 'weights', 'last.pt')
train.best_pt = bast_pt_path train.best_pt = bast_pt_path

View File

@ -14,6 +14,8 @@ def read_csv(file_path):
next(csv_reader) next(csv_reader)
result_row = [] result_row = []
for row in csv_reader: for row in csv_reader:
if row is None:
break
result_row.append(row) result_row.append(row)
return result_row return result_row
return None return None

View File

@ -10,29 +10,29 @@ def get_server_info():
# 1. 系统基本信息 # 1. 系统基本信息
info["system"] = { info["system"] = {
"OS": platform.system(), "os": platform.system(),
"OS版本": platform.version(), "os_version": platform.version(),
"主机名": platform.node(), "node": platform.node(),
"架构": platform.machine(), "machine": platform.machine(),
"处理器型号": platform.processor(), "processor": platform.processor(),# 处理器型号
"启动时间": datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S") "boot_time": datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S") # 启动时间
} }
# 2. CPU 信息 # 2. CPU 信息
cpu_usage = psutil.cpu_percent(interval=1) cpu_usage = psutil.cpu_percent(interval=1)
info["cpu"] = { info["cpu"] = {
"物理核心数": psutil.cpu_count(logical=False), "cpu_count": psutil.cpu_count(logical=False),
"逻辑核心数": psutil.cpu_count(logical=True), "cpu_count_logical": psutil.cpu_count(logical=True),
"当前使用率 (%)": cpu_usage, "cpu_usage": cpu_usage,
"每个核心使用率": psutil.cpu_percent(interval=1, percpu=True) "cpu_percent": psutil.cpu_percent(interval=1, percpu=True)
} }
# 3. 内存信息 # 3. 内存信息
mem = psutil.virtual_memory() mem = psutil.virtual_memory()
info["memory"] = { info["memory"] = {
"总内存 (GB)": round(mem.total / (1024**3), 2), "total": round(mem.total / (1024**3), 2),
"可用内存 (GB)": round(mem.available / (1024**3), 2), "available": round(mem.available / (1024**3), 2),
"使用率 (%)": mem.percent "percent": mem.percent
} }
# 4. 磁盘信息 # 4. 磁盘信息
@ -40,20 +40,20 @@ def get_server_info():
for partition in psutil.disk_partitions(): for partition in psutil.disk_partitions():
usage = psutil.disk_usage(partition.mountpoint) usage = psutil.disk_usage(partition.mountpoint)
disks.append({ disks.append({
"设备": partition.device, "device": partition.device,
"挂载点": partition.mountpoint, "mountpoint": partition.mountpoint,
"文件系统": partition.fstype, "fstype": partition.fstype,
"总空间 (GB)": round(usage.total / (1024**3), 2), "total": round(usage.total / (1024**3), 2),
"已用空间 (GB)": round(usage.used / (1024**3), 2), "used": round(usage.used / (1024**3), 2),
"使用率 (%)": usage.percent "percent": usage.percent
}) })
info["disks"] = disks info["disks"] = disks
# 5. 网络信息 # 5. 网络信息
net = psutil.net_io_counters() net = psutil.net_io_counters()
info["network"] = { info["network"] = {
"发送流量 (MB)": round(net.bytes_sent / (1024**2), 2), "bytes_sent": round(net.bytes_sent / (1024**2), 2),
"接收流量 (MB)": round(net.bytes_recv / (1024**2), 2) "bytes_recv": round(net.bytes_recv / (1024**2), 2)
} }
# 6. 进程信息示例前5个高CPU进程 # 6. 进程信息示例前5个高CPU进程
@ -64,10 +64,10 @@ def get_server_info():
if proc.info['cpu_percent'] > 0: if proc.info['cpu_percent'] > 0:
processes.append({ processes.append({
"PID": proc.info['pid'], "PID": proc.info['pid'],
"进程名": proc.info['name'], "name": proc.info['name'],
"CPU使用率 (%)": proc.info['cpu_percent'] "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 return info