File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from concurrent .futures import ThreadPoolExecutor
1+ import functools
2+ from concurrent .futures import ProcessPoolExecutor
23
34from chess_utils import fen_to_tensor
45from my_torch import Network
78from .labels import vector_to_label
89
910
11+ def process_fen (network : Network , encoding : str , fen : str ):
12+ try :
13+ output = network .predict (fen_to_tensor (fen , encoding = encoding ))
14+ return vector_to_label (output )
15+ except Exception as e :
16+ return f"Error: { e } "
17+
18+
1019def predict_mode (
1120 network : Network , chessfile : str , encoding : str = "simple"
1221) -> None :
1322 fens = load_chessfile_predict (chessfile )
1423
15- def process_fen (fen ):
16- try :
17- x = fen_to_tensor (fen , encoding = encoding )
18- output = network .predict (x )
19- label = vector_to_label (output )
20- return label
21- except Exception as e :
22- return f"Error: { e } "
23-
24- with ThreadPoolExecutor (max_workers = 4 ) as executor :
25- results = executor .map (process_fen , fens )
24+ dispatch = functools .partial (process_fen , network , encoding )
25+
26+ with ProcessPoolExecutor (max_workers = 4 ) as executor :
27+ results = executor .map (dispatch , fens )
2628
2729 for result in results :
2830 print (result )
You can’t perform that action at this time.
0 commit comments