import json
import os
path ='/mnt/tiger/Zhengsc/vessel/nnUNet_raw/Task01/dataset.json'
name = os.listdir('/mnt/tiger/Zhengsc/vessel/nnUNet_raw/Task01/imagesTr')
name_test = os.listdir('/mnt/tiger/Zhengsc/vessel/nnUNet_raw/Task01/imagesTs')
with open(path, "w+", encoding="utf-8") as f:
f.write('{\n')
f.write('"name": "Liver",\n')
f.write('"description": "Liver,and cancer segmentation",\n')
f.write('"reference": "xxxx",\n')
f.write('"licence": "CC-BY-SA 4.0",\n')
f.write('"release": "1.0 04/05/2018",\n')
f.write('"tensorImageSize": "3D",\n')
f.write('"modality": {\n')
f.write('"0": "CT"\n')
f.write('},\n\n')
f.write('"labels": {\n')
f.write('"0": "background",\n')
f.write('"1": "liver"\n},\n')
f.write('"numTraining": 0,\n')
f.write('"numTest":1,\n')
f.write('"training":[')
beforeI = '{"image":"./imagesTr/'
beforeL = '","label":"./labelsTr/'
for i in range(0,302):
f.write(beforeI)
f.write(name[i][-24:])
f.write(beforeL)
f.write(name[i][-24:])
f.write('"}')
print(name[i][-24:])
if i<302:
f.write(',')
f.write('],\n')
f.write('"test":[')
for i in range(0,140):
f.write('"./imagesTs/'+name_test[i][-24:]+'"')
if i<140:
f.write(',')
f.write(']\n}')
print('hello')
#