MCPcopy Create free account
hub / github.com/InternScience/SciReason / run

Method run

tools/prediction_merger.py:32–72  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

30 self.work_dir = self.cfg.get('work_dir')
31
32 def run(self):
33 filename = get_infer_output_path(
34 self.model_cfg, self.dataset_cfg,
35 os.path.join(self.work_dir, 'predictions'))
36 root, ext = os.path.splitext(filename)
37 partial_filename = root + '_0' + ext
38
39 if os.path.exists(
40 os.path.realpath(filename)) and not self.cfg['force']:
41 return
42
43 if not os.path.exists(os.path.realpath(partial_filename)):
44 print(f'{filename} not found')
45 return
46
47 # Load predictions
48 partial_filenames = []
49 preds, offset = {}, 0
50 i = 1
51 while os.path.exists(os.path.realpath(partial_filename)):
52 partial_filenames.append(os.path.realpath(partial_filename))
53 _preds = mmengine.load(partial_filename)
54 partial_filename = root + f'_{i}' + ext
55 i += 1
56 for _o in range(len(_preds)):
57 preds[str(offset)] = _preds[str(_o)]
58 offset += 1
59
60 dataset = build_dataset_from_cfg(self.dataset_cfg)
61 if len(preds) != len(dataset.test):
62 print('length mismatch')
63 return
64
65 print(f'Merge {partial_filenames} to {filename}')
66 with open(filename, 'w', encoding='utf-8') as f:
67 json.dump(preds, f, indent=4, ensure_ascii=False)
68
69 if self.cfg['clean']:
70 for partial_filename in partial_filenames:
71 print(f'Remove {partial_filename}')
72 os.remove(partial_filename)
73
74
75def dispatch_tasks(cfg):

Callers 1

dispatch_tasksFunction · 0.45

Calls 4

get_infer_output_pathFunction · 0.90
build_dataset_from_cfgFunction · 0.90
openFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected