chore: 同步最新实现代码(FP16 导出 / 轻量教师入口)与更新后的训练素材清单
Browse files- code/siai_all.py +31 -0
code/siai_all.py
CHANGED
|
@@ -7,6 +7,37 @@ from functools import lru_cache
|
|
| 7 |
import cv2, numpy as np, torch, torch.nn as nn
|
| 8 |
from torch.utils.data import DataLoader, Dataset, Sampler
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
DATA = r"D:\sfdp-ai\siamese\data"
|
| 11 |
TILES = os.environ.get("SFDP_TILES") or os.path.join(DATA, "tiles")
|
| 12 |
LABELS = os.path.join(DATA, "labels")
|
|
|
|
| 7 |
import cv2, numpy as np, torch, torch.nn as nn
|
| 8 |
from torch.utils.data import DataLoader, Dataset, Sampler
|
| 9 |
|
| 10 |
+
class _Tee:
|
| 11 |
+
"""把 stdout/stderr 同时写到一份可由外部读取的实时日志。"""
|
| 12 |
+
def __init__(self, *streams):
|
| 13 |
+
self.streams = streams
|
| 14 |
+
|
| 15 |
+
def write(self, s):
|
| 16 |
+
for st in self.streams:
|
| 17 |
+
try:
|
| 18 |
+
st.write(s)
|
| 19 |
+
except Exception:
|
| 20 |
+
pass
|
| 21 |
+
return len(s)
|
| 22 |
+
|
| 23 |
+
def flush(self):
|
| 24 |
+
for st in self.streams:
|
| 25 |
+
try:
|
| 26 |
+
st.flush()
|
| 27 |
+
except Exception:
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
_live = os.environ.get("SFDP_LIVE_LOG")
|
| 32 |
+
if _live:
|
| 33 |
+
try:
|
| 34 |
+
_lf = open(_live, "a", encoding="utf-8", buffering=1)
|
| 35 |
+
sys.stdout = _Tee(sys.stdout, _lf)
|
| 36 |
+
sys.stderr = _Tee(sys.stderr, _lf)
|
| 37 |
+
except Exception:
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
|
| 41 |
DATA = r"D:\sfdp-ai\siamese\data"
|
| 42 |
TILES = os.environ.get("SFDP_TILES") or os.path.join(DATA, "tiles")
|
| 43 |
LABELS = os.path.join(DATA, "labels")
|