MONAI怎么读取image,label不报错

在使用MONAI框架时遇到报错,本文详细介绍了如何排查和解决数据格式问题,特别是针对label的异常处理,包括dicom转nii批处理、数据归一化、错误定位以及ROI设置的调整,确保训练过程的顺利进行。
摘要由CSDN通过智能技术生成

 当运行MONAI框架一直报错的情况下。

1. 不要慌

2. 查看数据格式是否有问题,dicom转nii批处理代码如下,使用dcmrtstruct2nii包

#!/usr/bin/env python
# coding: utf-8

# In[21]:


#separate labels from folder to dicom_label
import os
import shutil

def find_file_starts(path):
    finds = []
    for i, j, k in os.walk(path):
        for file in k:
            if file.startswith("RS"):
                print(os.path.join(i, file))
                finds.append(os.path.join(i, file))
    return finds           

                
def movefile(oripath,tardir):
    filename = os.path.basename(oripath)
    tarpath = os.path.join(tardir, filename)
    #判断原始文件路劲是否存在
    if not os.path.exists(oripath):
        print('the dir is not exist:%s' % oripath)
        status = 0
    else:
     #判断目标文件夹是否存在
        if os.path.exists(tardir):
        #判断目标文件夹里原始文件是否存在,存在则删除
            if os.path.exists(tarpath):
                os.remove(tarpath)
        else:
         #目标文件夹不存在则创建目标文件夹
            os.makedirs(tardir)
          #移动文件
        shutil.move(oripath, tardir)

        status = 1

    return status

##for CTV
path_2_all_patients = r'C:\Users\jinpe\Desktop\MONAI_SEG\dataset\sis_trial\CTV\dicom_CT'
label_files = find_file_starts(path_2_all_patients)
tardir_loc = r'C:\Users\jinpe\Desktop\MONAI_SEG\dataset\sis_trial\CTV\dicom_label'
for file in label_files:
    movefile(file,tardir_loc)

##for OAR
path_2_all_patients = r'C:\Users\jinpe\Desktop\MONAI_SEG\dataset\sis_trial\OAR\dicom_CT'
patient_names = os.listdir(path_2_all_patients)

label_files = find_file_starts(path_2_all_patients)
tardir_loc = r'C:\Users\jinpe\Desktop\MONAI_SEG\dataset\sis_trial\OAR\dicom_label'
#Due to different sort for label files, have to rename the labels and CTs
for i,file in enumerate(label_files):
    new_name = file.replace("RS",str(i)+"RS")
    new_name = os.path.join(tardir_loc,os.path.basename(new_name))
    print(new_name)
    os.rename(file,new_name)#rename and copy the label
    #movefile(file,tardir_loc)
    
for i,patient in enumerate(patient_names):
    os.rename(os.path.join(path_2_all_patients,patient),os.path.join(path_2_all_patients,str(i)+patient))#rename the dicom CT


# In[ ]:


'''
#optional
#transform dicom_CT to nii_CT
!python -c "import dicom2nifti" || pip install -q dicom2nifti
import os
path_2_all_patients = r'C:\Users\jinpe\Desktop\MONAI_SEG\dataset\sis_trial\dicom_CT'
patients_folders = os.listdir(path_2_all_patients)
path_out_data = r'C:\Users\jinpe\Desktop\MONAI_SEG\dataset\sis_trial\nii_CT'
print(patients_folders)

for i, patient in enumerate(patients_folders):
    dicom2nifti.dicom_series_to_nifti(os.path.join(path_2_all_patients, patient), os.path.join(path_out_data, str(i)+"_"+patien
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
阿里的DataV和京东的莫奈都是优秀的大数据可视化平台,但是在以下几个方面存在一些差异: 1. 技术架构:DataV采用了基于Kubernetes的容器化架构,可以快速扩展、自动化部署和管理,同时支持多云部署;莫奈则采用了基于Spark的分布式计算架构,支持GPU加速,能够快速处理大规模数据。 2. 用户群体:DataV更注重企业级用户,提供了丰富的企业级功能和服务,支持多种数据源接入,适用于金融、电商、物流等行业的大屏展示和实时监控;而莫奈则更注重学术机构、政府部门等研究型用户,提供了多种数据挖掘和预测分析算法和模型。 3. 功能模块:DataV提供了多种实时数据接入和展示方式,支持多种数据可视化图表和报表,同时提供了数据分析和预测分析算法和模型;而莫奈则更注重数据挖掘和预测分析功能,提供了更加多样化的算法和模型库,同时支持地图可视化和物联网数据接入。 4. 扩展性:DataV提供了插件式开发和二次开发的方式,可以灵活地进行定制和扩展,支持多种开发语言和框架;而莫奈则更注重算法和模型的扩展和优化,提供了多种扩展方式和可配置参数。 综上所述,阿里的DataV和京东的莫奈都是优秀的大数据可视化平台,但是在技术架构、用户群体、功能模块和扩展性方面存在一些差异。用户可以根据自身需求选择不同的平台,或者结合两个平台的优势进行定制开发。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值