M3D-Seg / data_load_demo.py
GoodBaiBai88's picture
Upload 4 files
79856c8 verified
raw
history blame
722 Bytes
import numpy as np
from scipy import sparse
import ast
import os
import json
uniseg_path = '/zhaobai/joint_data/UniSeg' # your path
dataset_code = '0012'
json_path = os.path.join('./', dataset_code, dataset_code + '.json')
with open(json_path, 'r') as f:
dataset_dict = json.load(f)
ct_file_path = os.path.join(uniseg_path, dataset_dict['training'][0]['image'])
gt_file_path = os.path.join(uniseg_path, dataset_dict['training'][0]['label'])
img_array = np.load(ct_file_path)[0]
print('img_array.shape ', img_array.shape)
allmatrix_sp= sparse.load_npz(gt_file_path)
gt_shape = ast.literal_eval(gt_file_path.split('.')[-2])
gt_array=allmatrix_sp.toarray().reshape(gt_shape)
print('gt_array.shape ', gt_array.shape)