?
This commit is contained in:
@@ -74,6 +74,7 @@ def run_action_subprocess(mp4_path: Path, settings: Settings) -> str:
|
||||
cwd=str(settings.fish_action_root),
|
||||
env=os.environ.copy(),
|
||||
log_name="FishAction",
|
||||
stream_to_logger=False,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
err = proc.stdout or ""
|
||||
@@ -87,7 +88,7 @@ def run_action_subprocess(mp4_path: Path, settings: Settings) -> str:
|
||||
if not rows:
|
||||
raise RuntimeError("Empty prediction JSON")
|
||||
pred_en = str(rows[0].get("pred_3class", "")).strip().lower()
|
||||
logger.info(
|
||||
logger.debug(
|
||||
"[FishAction] prediction row:\n{}",
|
||||
format_json_pretty(rows[0]),
|
||||
)
|
||||
|
||||
@@ -102,6 +102,7 @@ def run_measure_subprocess(svo_path: Path, settings: Settings) -> None:
|
||||
cwd=str(settings.fish_measure_root),
|
||||
env=os.environ.copy(),
|
||||
log_name="FishMeasure",
|
||||
stream_to_logger=False,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
err = proc.stdout or ""
|
||||
@@ -581,28 +582,28 @@ def build_measure_snapshot(svo_path: Path, settings: Settings) -> MeasureSnapsho
|
||||
data = _load_weight_json(svo_path, settings)
|
||||
summary = data.get("dgcnn_summary") or data.get("weight_summary") or {}
|
||||
|
||||
weight_g = summary.get("avg_predicted_weight_g")
|
||||
length_mm = summary.get("avg_length_input_topk")
|
||||
if weight_g is None:
|
||||
weight_g = data.get("avg_predicted_weight_g")
|
||||
if length_mm is None:
|
||||
length_mm = summary.get("avg_length_input") or data.get("avg_length_input")
|
||||
result = _result_from_weight_prediction(data)
|
||||
|
||||
result: List[Dict[str, Any]] = []
|
||||
if weight_g is not None and length_mm is not None:
|
||||
try:
|
||||
w = float(weight_g)
|
||||
l = float(length_mm)
|
||||
if math.isfinite(w) and math.isfinite(l):
|
||||
result = [{"id": 1, "weight": w, "length": l}]
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
if not result:
|
||||
weight_g = summary.get("avg_predicted_weight_g")
|
||||
length_mm = summary.get("avg_length_input_topk")
|
||||
if weight_g is None:
|
||||
weight_g = data.get("avg_predicted_weight_g")
|
||||
if length_mm is None:
|
||||
length_mm = summary.get("avg_length_input") or data.get("avg_length_input")
|
||||
if weight_g is not None and length_mm is not None:
|
||||
try:
|
||||
w = float(weight_g)
|
||||
l = float(length_mm)
|
||||
if math.isfinite(w) and math.isfinite(l):
|
||||
result = [{"id": 1, "weight": w, "length": l}]
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
logger.info(
|
||||
"[FishMeasure] parsed {}\navg_weight_g(top5)={} avg_length_mm(top5)={}\nresult:\n{}\ndgcnn_summary:\n{}",
|
||||
"[FishMeasure] parsed {}\nresult ({} fish):\n{}\ndgcnn_summary:\n{}",
|
||||
svo_path.name,
|
||||
weight_g,
|
||||
length_mm,
|
||||
len(result),
|
||||
format_json_pretty(result),
|
||||
format_json_pretty(summary if summary else {}),
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""子进程运行并把 stdout/stderr 流式写入 loguru,便于查看 FishMeasure / FishAction 中间输出。"""
|
||||
"""子进程运行并把 stdout/stderr 合并;可选将逐行输出写入 loguru(测量/行为推理可关闭以减少日志)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -15,10 +15,12 @@ def run_subprocess_with_log(
|
||||
cwd: str,
|
||||
env: Optional[Dict[str, str]] = None,
|
||||
log_name: str,
|
||||
stream_to_logger: bool = True,
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
"""运行子进程,合并 stderr 到 stdout,按行输出到 loguru。
|
||||
"""运行子进程,合并 stderr 到 stdout,可选按行输出到 loguru。
|
||||
|
||||
返回 CompletedProcess,stdout 为完整输出,便于失败时拼进异常信息。
|
||||
``stream_to_logger=False`` 时不把子进程逐行写入日志(仍完整收集 stdout)。
|
||||
"""
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
@@ -33,9 +35,10 @@ def run_subprocess_with_log(
|
||||
if proc.stdout is not None:
|
||||
for line in proc.stdout:
|
||||
lines.append(line)
|
||||
s = line.rstrip()
|
||||
if s:
|
||||
logger.info("[{}] {}", log_name, s)
|
||||
if stream_to_logger:
|
||||
s = line.rstrip()
|
||||
if s:
|
||||
logger.info("[{}] {}", log_name, s)
|
||||
rc = proc.wait()
|
||||
out = "".join(lines)
|
||||
return subprocess.CompletedProcess(cmd, rc, out, "")
|
||||
|
||||
Reference in New Issue
Block a user