MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / datafold_read

Function datafold_read

monai/auto3dseg/utils.py:232–268  ·  view source on GitHub ↗

Read a list of data dictionary `datalist` Args: datalist: the name of a JSON file listing the data, or a dictionary. basedir: directory of image files. fold: which fold to use (0..1 if in training set). key: usually 'training' , but can try 'validation' or '

(datalist: str | dict, basedir: str, fold: int = 0, key: str = "training")

Source from the content-addressed store, hash-verified

230
231
232def datafold_read(datalist: str | dict, basedir: str, fold: int = 0, key: str = "training") -> tuple[list, list]:
233 """
234 Read a list of data dictionary `datalist`
235
236 Args:
237 datalist: the name of a JSON file listing the data, or a dictionary.
238 basedir: directory of image files.
239 fold: which fold to use (0..1 if in training set).
240 key: usually 'training' , but can try 'validation' or 'testing' to get the list data without labels (used in challenges).
241
242 Returns:
243 A tuple of two arrays (training, validation).
244 """
245
246 if isinstance(datalist, str):
247 json_data = ConfigParser.load_config_file(datalist)
248 else:
249 json_data = datalist
250
251 dict_data = deepcopy(json_data[key])
252
253 for d in dict_data:
254 for k, _ in d.items():
255 if isinstance(d[k], list):
256 d[k] = [os.path.join(basedir, iv) for iv in d[k]]
257 elif isinstance(d[k], str):
258 d[k] = os.path.join(basedir, d[k]) if len(d[k]) > 0 else d[k]
259
260 tr = []
261 val = []
262 for d in dict_data:
263 if "fold" in d and d["fold"] == fold:
264 val.append(d)
265 else:
266 tr.append(d)
267
268 return tr, val
269
270
271def verify_report_format(report: dict, report_format: dict) -> bool:

Calls 2

load_config_fileMethod · 0.80
appendMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…