当前位置:网站首页>使用 load_decathlon_datalist (MONAI)快速加载JSON数据
使用 load_decathlon_datalist (MONAI)快速加载JSON数据
2022-07-07 08:28:00 【Tina姐】

思考:当你有一个包含数据所有信息的 JSON 文件的时候,怎么加载到 MONAI 框架里面?
如图所示,从这个json文件里可以知道数据的label信息,每个类别的真实含义。以及它的模态是CT,图像是3D 并且把训练集、验证集和测试接包含的图像地址都写上了。
我们只要通过这个文件就可以把数据喂给模型。
在 MONAI 里确实提供了加载 json 格式数据的方式。非常方便。
同理,我们可以把自己的数据也写成 json 格式加载。
本节教程将涉及这两个内容,感兴趣的一起来看看吧
load_decathlon_datalist 加载数据
哪里调用?
from monai.data import load_decathlon_datalist
函数参数
load_decathlon_datalist(data_list_file_path: PathLike,is_segmentation: bool = True, data_list_key: str = “training”, base_dir: Optional[PathLike] = None,)
Args:
- data_list_file_path: the path to the json file of datalist. 你的 json 文件地址
- is_segmentation: whether the datalist is for segmentation task, default is True. 是否是分割任务
- data_list_key: the key to get a list of dictionary to be used, default is “training”. 你要加载哪个数据集(traning, validation, test), 这里的key值得是 json 文件中对应数据集名字(看上图)。
- base_dir: the base directory of the dataset, if None, use the datalist directory.数据的主目录。从图片可以知道,数据的地址是从imagesTs/imagesTr/labelsTr 开始的。而这些地址的上一级地址需要提供。不填写的话,默认和json文件在同一个目录下。
演示示例:
我在tested.py文件里加载数据
from monai.data import load_decathlon_datalist
data_dir = "dataset/dataset.json"
datalist = load_decathlon_datalist(data_dir, True, "training
# datalist = load_decathlon_datalist(data_dir, True, "training", 'dataset') 加上base_dir

这样,符合 MONAI data 的字典就创建好了。
我们可以看到,有这个 json 文件,我们可以很方便的创建数据。
接下来,我们看一下如何创建这个json文件
创建数据 json 文件
from collections import OrderedDict
import json
json_dict = OrderedDict()
json_dict['name'] = "your task"
json_dict['description'] = "btcv yucheng"
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": "CT",
}
json_dict['test'] = [
"imagesTs/img0061.nii.gz",
"imagesTs/img0062.nii.gz",
"imagesTs/img0063.nii.gz",
"imagesTs/img0064.nii.gz",
"imagesTs/img0065.nii.gz",
"imagesTs/img0066.nii.gz"] # 把包含数据的列表写进来。
# 想保存什么信息,在json_dict里面增加一个字典数据即可
# 保存json
with open(os.path.join(out_base, "dataset.json"), 'w') as f:
json.dump(json_dict, f, indent=4, separators=(',', ': '))
文章持续更新,可以关注微信公众号【医学图像人工智能实战营】获取最新动态,一个关注于医学图像处理领域前沿科技的公众号。坚持已实践为主,手把手带你做项目,打比赛,写论文。凡原创文章皆提供理论讲解,实验代码,实验数据。只有实践才能成长的更快,关注我们,一起学习进步~
我是Tina, 我们下篇博客见~
白天工作晚上写文,呕心沥血
觉得写的不错的话最后,求点赞,评论,收藏。或者一键三连
边栏推荐
- JMeter loop controller and CSV data file settings are used together
- Remote meter reading, switching on and off operation command
- 串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
- Jump to the mobile terminal page or PC terminal page according to the device information
- 深入理解Apache Hudi异步索引机制
- High number_ Chapter 1 space analytic geometry and vector algebra_ Quantity product of vectors
- 【acwing】789. 数的范围(二分基础)
- 2022.7.4DAY596
- Sword finger offer 38 Arrangement of strings [no description written]
- table宽度比tbody宽度大4px
猜你喜欢

Leetcode exercise - 113 Path sum II

串口通讯继电器-modbus通信上位机调试软件工具项目开发案例

AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these

Serial communication relay Modbus communication host computer debugging software tool project development case

Review of the losers in the postgraduate entrance examination

JMeter about setting thread group and time

P1223 排队接水/1319:【例6.1】排队接水

01 use function to approximate cosine function (15 points)

How to cancel automatic saving of changes in sqlyog database

Talking about the return format in the log, encapsulation format handling, exception handling
随机推荐
CSAPP Bomb Lab 解析
关于easyflash v3.3使用过程的记录
[homework] 2022.7.6 write your own cal function
PDF文档签名指南
@Configuration, use, principle and precautions of transmission:
leetcode-560:和为 K 的子数组
IPv4 socket address structure
Review of the losers in the postgraduate entrance examination
01 use function to approximate cosine function (15 points)
C logging method
[牛客网刷题 Day5] JZ77 按之字形顺序打印二叉树
MySQL insert data create trigger fill UUID field value
字符串格式化
【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法
ArrayList线程不安全和解决方案
BigDecimal数值比较
JMeter loop controller and CSV data file settings are used together
2022.7.6DAY598
施努卡:机器人视觉抓取工作原理 机器视觉抓取
Talking about the return format in the log, encapsulation format handling, exception handling