89 lines
4.1 KiB
Python
89 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from ...commands import CommandSpec, append_flag, bash, conda_python, required
|
|
from ...config import settings
|
|
|
|
|
|
DATASET_TOOL_DIR = settings.source_root / "DataSet_Own" / "1. 图片预处理(内含使用手册)"
|
|
STACK_TOOL_DIR = settings.source_root / "Tool-图片堆叠"
|
|
VIDEO_DIR = settings.source_root / "Seg_Predict_Own_Video_V2"
|
|
YOLO_DATASET_DIR = settings.source_root / "Seg_All_In_One_YoloModel" / "Yolo数据集构建"
|
|
|
|
|
|
def _dataset_script(name: str) -> Path:
|
|
return DATASET_TOOL_DIR / name
|
|
|
|
|
|
def build_dataset_task(job_type: str, params: dict, conda_env: str) -> CommandSpec | None:
|
|
if job_type == "dataset.rename":
|
|
args = bash(_dataset_script("1_rename_pics.sh"))
|
|
append_flag(args, "-i", required(params, "image_dir"))
|
|
append_flag(args, "-l", required(params, "label_dir"))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "rename and normalize image/label names")
|
|
|
|
if job_type == "dataset.to_png":
|
|
script = _dataset_script("2_1_Trans_to_png.py")
|
|
args = conda_python(conda_env, script)
|
|
append_flag(args, "-i", params.get("input_dir"))
|
|
append_flag(args, "-o", params.get("output_dir"))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "convert images to png")
|
|
|
|
if job_type == "dataset.resize":
|
|
args = bash(_dataset_script("2_reformate_pics.sh"))
|
|
append_flag(args, "-i", params.get("image_dir"))
|
|
append_flag(args, "-l", params.get("label_dir"))
|
|
append_flag(args, "-w", params.get("width", 1920))
|
|
append_flag(args, "-h", params.get("height", 1080))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "resize and reformat image/label folders")
|
|
|
|
if job_type == "dataset.pair":
|
|
args = bash(_dataset_script("3_pair_ori_label.sh"))
|
|
append_flag(args, "-i", required(params, "image_dir"))
|
|
append_flag(args, "-l", required(params, "label_dir"))
|
|
append_flag(args, "-p", params.get("prefix", ""))
|
|
append_flag(args, "-s", params.get("suffix", ""))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "check image and label pairing")
|
|
|
|
if job_type == "dataset.rebuild_labels":
|
|
args = bash(_dataset_script("4_rebuild_labels.sh"))
|
|
append_flag(args, "-l", required(params, "label_dir"))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "rebuild color labels into GT masks")
|
|
|
|
if job_type == "dataset.stack":
|
|
args = bash(_dataset_script("5_TOOL_stack_pics.sh"))
|
|
append_flag(args, "-i", required(params, "image_dir"))
|
|
append_flag(args, "-l", required(params, "label_dir"))
|
|
append_flag(args, "-r", required(params, "result_dir"))
|
|
append_flag(args, "-a", params.get("alpha", 0.3))
|
|
append_flag(args, "-p", params.get("prefix", ""))
|
|
append_flag(args, "-s", params.get("suffix", ""))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "overlay image and label for inspection")
|
|
|
|
if job_type == "dataset.stitch":
|
|
args = bash(_dataset_script("6_TOOL_stitch_pics.sh"))
|
|
append_flag(args, "-i", required(params, "image_dir"))
|
|
append_flag(args, "-l", required(params, "label_dir"))
|
|
append_flag(args, "-r", required(params, "result_dir"))
|
|
return CommandSpec(args, DATASET_TOOL_DIR, "stitch image and label panels")
|
|
|
|
if job_type == "dataset.video_frames":
|
|
script = VIDEO_DIR / "1_Save_Frame_V2.py"
|
|
args = conda_python(conda_env, script)
|
|
append_flag(args, "--video", required(params, "video"))
|
|
append_flag(args, "--interval", params.get("interval", 0.5))
|
|
append_flag(args, "--resize", params.get("resize"))
|
|
append_flag(args, "--output_dir", params.get("output_dir"))
|
|
return CommandSpec(args, VIDEO_DIR, "extract video frames into DataSet_Public layout")
|
|
|
|
if job_type == "dataset.yolo_check_pairs":
|
|
script = YOLO_DATASET_DIR / "0_1_check_picture_pair.py"
|
|
args = conda_python(conda_env, script)
|
|
append_flag(args, "-i", required(params, "image_dir"))
|
|
append_flag(args, "-l", required(params, "label_dir"))
|
|
return CommandSpec(args, YOLO_DATASET_DIR, "check YOLO image/label pairs")
|
|
|
|
return None
|
|
|