From 723bfdf2d9d0742a4800164587b25d1703c40857 Mon Sep 17 00:00:00 2001 From: ClovertaTheTrilobita Date: Fri, 17 Oct 2025 11:58:14 +0000 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E6=96=B0=E5=A2=9E=E6=9B=B4?= =?UTF-8?q?=E5=A4=9A=E6=8E=A5=E5=8F=A3=20feat(frontend):=20=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=A0=B7=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/cp_train.py | 36 ++++++-- backend/flaskApp.py | 24 ++++- frontend/index.html | 143 ++++++++++++++++++++++++++--- frontend/preview.html | 153 +++++++++++++++++++++++++++++-- frontend/run.html | 167 +++++++++++++++++++++++++++++++++- frontend/train.html | 203 ++++++++++++++++++++++++++++++++---------- 6 files changed, 653 insertions(+), 73 deletions(-) diff --git a/backend/cp_train.py b/backend/cp_train.py index d6d9aa4..58594ac 100644 --- a/backend/cp_train.py +++ b/backend/cp_train.py @@ -5,6 +5,8 @@ import redis import datetime import json +from sympy import false + CONFIG_PATH = Path(__file__).parent / "config.yaml" cfg = OmegaConf.load(CONFIG_PATH) cfg.data.root_dir = str((CONFIG_PATH.parent / cfg.data.root_dir).resolve()) @@ -34,11 +36,25 @@ class Cptrain: @classmethod async def start_train(cls, - time: str | None = None, - model_name: str | None = None, - image_filter: str = "_img", - mask_filter: str = "_masks", - base_model: str = "cpsam"): + time: str | None = None, + model_name: str | None = None, + image_filter: str = "_img", + mask_filter: str = "_masks", + base_model: str = "cpsam", + train_probs: list[float] = None, + test_probs: list[float] = None, + batch_size: int = 8, + learning_rate = 5e-5, + n_epochs: int = 100, + weight_decay=0.1, + normalize: bool =True, + compute_flows: bool = False, + min_train_masks: int = 5, + nimg_per_epoch: int =None, + rescale: bool= False, + scale_range=None, + channel_axis: int = None, + ): train_dir = Path(TRAIN_DIR) / time test_dir = Path(TEST_DIR) / time @@ -56,9 +72,13 @@ class Cptrain: model_path, train_losses, test_losses = train.train_seg(model.net, train_data=images, train_labels=labels, test_data=test_images, test_labels=test_labels, - weight_decay=0.1, learning_rate=1e-5, - n_epochs=100, model_name=model_name, - save_path=BASE_DIR) + train_probs=train_probs, test_probs=test_probs, + weight_decay=weight_decay, learning_rate=learning_rate, + n_epochs=n_epochs, model_name=model_name, + save_path=BASE_DIR, batch_size=batch_size, + normalize=normalize, compute_flows=compute_flows, min_train_masks=min_train_masks, + nimg_per_epoch=nimg_per_epoch, rescale=rescale, scale_range=scale_range, channel_axis=channel_axis + ) set_status(time, "done", train_losses, test_losses) print("模型已保存到:", model_path) diff --git a/backend/flaskApp.py b/backend/flaskApp.py index bcf20d0..e3c14b9 100644 --- a/backend/flaskApp.py +++ b/backend/flaskApp.py @@ -145,6 +145,17 @@ def train_upload(): image_filter = request.args.get("image_filter") or "_img" mask_filter = request.args.get("mask_filter") or "_masks" base_model = request.args.get("base_model") or "cpsam" + batch_size = request.args.get("batch_size") or 8 + learning_rate = request.args.get("learning_rate") or 5e-5 + n_epochs = request.args.get("n_epochs") or 100 + weight_decay = request.args.get("weight_decay") or 0.1 + normalize = request.args.get("normalize") or True + compute_flows = request.args.get("compute_flows") or False + min_train_masks = request.args.get(" min_train_masks") or 5 + nimg_per_epoch = request.args.get("nimg_per_epoch") or None + rescale = request.args.get("rescale") or False + scale_range = request.args.get("scale_range") or None + channel_axis = request.args.get("channel_axis") or None train_files = request.files.getlist("train_files") test_files = request.files.getlist("test_files") @@ -172,7 +183,18 @@ def train_upload(): model_name=model_name, image_filter=image_filter, mask_filter=mask_filter, - base_model=base_model + base_model=base_model, + batch_size=batch_size, + learning_rate=learning_rate, + n_epochs=n_epochs, + weight_decay=weight_decay, + normalize=normalize, + compute_flows=compute_flows, + min_train_masks=min_train_masks, + nimg_per_epoch=nimg_per_epoch, + rescale=rescale, + scale_range=scale_range, + channel_axis=channel_axis, )) fut = executor.submit(job) diff --git a/frontend/index.html b/frontend/index.html index 7a0a62d..c3684bd 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,18 +1,139 @@ - - + - - - Bootstrap demo - + + + 任务面板 + + + + + + + +
+
+
+
+ + Cell Processing + +
- 运行 - 训练 +

欢迎使用任务面板

+

+ 选择你要进行的操作。可随时返回此页切换任务。 +

+ + + +
+ +
+ + 文档 + + + + 设置 + + + 快捷键:R 运行,T 训练 +
+
+
+
+ + + + + + - - \ No newline at end of file + diff --git a/frontend/preview.html b/frontend/preview.html index c2e61a8..c504e69 100644 --- a/frontend/preview.html +++ b/frontend/preview.html @@ -1,10 +1,149 @@ - -

运行结果预览

- - - + + + + 运行结果预览 + + + + + + + + +
+
+ +
+

+ 运行结果预览 +

+
+ 生成的图像/掩膜将显示在下方网格中 +
+
+ + + + + + + + +
+ +
+
+
+ + + + + \ No newline at end of file + + + diff --git a/frontend/run.html b/frontend/run.html index 0d88074..b6d54e6 100644 --- a/frontend/run.html +++ b/frontend/run.html @@ -10,7 +10,7 @@ -
+ + +
+
+ + +
+
+

选择文件

+ 可多选 +
+
+ + +
+
+ +
+ + +
+
+
+
+
+ flow threshold + +
+
+ +
+
+ cellprob threshold + +
+
+ +
+
+ diameter + +
+
+ +
+ +
+
+
+ + +
+
+
+ + 提示 +
+
+ • 参数留空将使用默认值。
+ • 数值可使用小数(如 0.4)。
+ • 选择合适的模型以获得更稳健的分割效果。 +
+
+
+
+ + +
+ + +
+
+ 进度 + +
+ +
+
+ +
+
@@ -184,6 +271,82 @@ } }); + + + \ No newline at end of file diff --git a/frontend/train.html b/frontend/train.html index c155218..514bb93 100644 --- a/frontend/train.html +++ b/frontend/train.html @@ -1,58 +1,171 @@ - - + - - - Bootstrap demo - + + + 训练任务 + + + + + + -
-
-
-
选择训练文件
- -
-
-
选择测试文件
- -
+
+
+ +
+

训练配置

+
选择训练/测试数据并设置模型参数
+
-
-
-
-
- model name: - -
- -
- image filter: - -
- -
- masks filter - -
- - - -
+ +
+
+
+ +
+ +
-
-
- - +
+
+ +
+ +
+
+
+ +
+ + +
+
+
+
+
+ model name + +
+
+ +
+
+ image filter + +
+
+ +
+
+ masks filter + +
+
+ +
+ +
+
+
+ + +
+
+
+ 提示 +
+
+ • 名称用于区分训练产物(日志/权重)。
+ • filter 用于匹配文件名,如 *_img.png*_masks.png
+ • 选择合适的预训练模型可加速收敛。 +
+
+
+
+ + +
+ +
+
+ 进度 + +
+ +
+
+
-


+
+ + +