然后在dataset_conversion文件中,新建一个py文件,用来生成对KiTS数据集做出描述的json文件dataset。(此处我还将其命名为Dataset040_KiTS)
代码内容如下:(此处参考博客nnUnet肾脏肿瘤分割实战(KiTS19)_宁远x的博客-CSDN博客_宁远x的博客-CSDN博客"),并做了一些改动)
import os
import json
import shutil
def save_json(obj, file, indent=4, sort_keys=True):
with open(file, 'w') as f:
json.dump(obj, f, sort_keys=sort_keys, indent=indent)
def maybe_mkdir_p(directory):
directory = os.path.abspath(directory)
splits = directory.split("/")[1:]
for i in range(0, len(splits)):
if not os.path.isdir(os.path.join("/", *splits[:i + 1])):
try:
os.mkdir(os.path.join("/", *splits[:i + 1]))
except FileExistsError:
# this