File size: 1,559 Bytes
c7aa71c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf-8 -*-
"""教师打标的轻量入口:只做目录扫描与 SfdpTeacher 调用,不加载 torch / cv2。



避免与训练同时启动时因 torch DLL 占用内存触发 WinError 1455(页面文件太小)。

"""
import os
import subprocess
import sys

TILES = r"D:\sfdp-ai\siamese\data\tiles"
LABELS = r"D:\sfdp-ai\siamese\data\labels"
TEACHER = r"D:\sfdp-ai\bin\SfdpTeacher.exe"


def main():
    os.makedirs(LABELS, exist_ok=True)
    print("SCAN_START", TILES, flush=True)
    dirs = sorted(d for d in os.listdir(TILES) if os.path.isdir(os.path.join(TILES, d)))
    print("SCAN_DIRS", len(dirs), flush=True)

    todo = []
    for i, d in enumerate(dirs):
        if not os.path.exists(os.path.join(LABELS, d + ".csv")):
            todo.append(d)
        if (i + 1) % 2000 == 0:
            print("SCAN", i + 1, "/", len(dirs), flush=True)
    print("DIRS", len(dirs), "TODO", len(todo), flush=True)

    for i, d in enumerate(todo):
        try:
            subprocess.run(
                [TEACHER, os.path.join(TILES, d), os.path.join(LABELS, d + ".csv"),
                 "--mode", "uhd", "--crop", "128", "--per-pair", "4", "--limit", "0"],
                stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=300,
            )
        except Exception as e:
            print("SKIP", d, repr(e), flush=True)
        if (i + 1) % 10 == 0:
            print("PROGRESS", i + 1, "/", len(todo), flush=True)
    print("DONE", flush=True)


if __name__ == "__main__":
    main()