1. 存放数据集的文件夹data内文件命名及内容不同
nnunetv1参考:nnUNetv1在linux平台上训练自己的数据集-CSDN博客
2. data.json文件内代码不同
# nnunetv2
# import setuptools
#
# if __name__ == "__main__":
# setuptools.setup()
#
#
# import json
#
# nnUNet_dir = '/home/chengj/student/lhh/nnU-Net/1/DATASET/'
# # 此路径根据自己实际修改
#
# def sts_json():
# info = {
# "channel_names": {
# "0": "CBCT"
# },
# "labels": {
# "background": 0,
# "pore": 1
# },
# # "training": 194,
# "numTraining": 194,
# "file_ending": ".nii.gz"
# }
# with open(nnUNet_dir + 'nnUNet_raw/nnUNet_raw_data/Task02_pore/dataset.json',
# 'w') as f:
# json.dump(info, f, indent=4)
#
# sts_json()# -*- coding: utf-8 -*-
"""
Created on 2023/9/26 10:02
@author: zhengjie
"""
# nnunetv1"""
创建数据集的json
""""""
创建数据集的json
"""import os
import json
from collections import OrderedDictpath_originalData = r"/home/chengj/student/lhh/nnU-Net/1/DATASET/nnUNet_raw/nnUNet_raw_data/Task02_pore"train_real_image = os.listdir((path_originalData + "/imagesTr"))
train_real_label = os.listdir((path_originalData + "/labelsTr"))
test_real_image = os.listdir((path_originalData + "/imagesTs"))# 对文件列表进行排序,以确保image和label一一对应
train_real_image = sorted(train_real_image)
train_real_label = sorted(train_real_label)
test_real_image = sorted(test_real_image)# 打印检查
print(train_real_image)
for idx in range(len(train_real_image)):print({'image': "./imagesTr/%s" % train_real_image[idx],"label": "./labelsTr/%s" % train_real_label[idx]})# 创建json文件内容
json_dict = OrderedDict()
json_dict['name'] = "pore"
json_dict['description'] = "Segmentation"
json_dict['tensorImageSize'] = "3D"
json_dict['reference'] = "see challenge website"
json_dict['licence'] = "see challenge website"
json_dict['release'] = "0.0"
json_dict['modality'] = {"0": "MRI"}# labels键在nnU-Net中应为整数键,值为字符串名称
json_dict['labels'] = {"0": "Background", "1": "pore"}json_dict['numTraining'] = len(train_real_image)
json_dict['numTest'] = len(test_real_image)
json_dict['file_ending'] = '.nii.gz'json_dict['training'] = []
for idx in range(len(train_real_image)):json_dict['training'].append({'image': "./imagesTr/%s" % train_real_image[idx],"label": "./labelsTr/%s" % train_real_label[idx]})json_dict['test'] = ["./imagesTs/%s" % i for i in test_real_image]with open(os.path.join(path_originalData, "dataset.json"), 'w') as f:json.dump(json_dict, f, indent=4, sort_keys=True)