当前位置:网站首页>使用 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, 我们下篇博客见~
白天工作晚上写文,呕心沥血
觉得写的不错的话最后,求点赞,评论,收藏。或者一键三连
边栏推荐
- 555电路详解
- [email protected] can help us get the log object quickly
- 深入分析ERC-4907协议的主要内容,思考此协议对NFT市场流动性意义!
- table宽度比tbody宽度大4px
- A small problem of bit field and symbol expansion
- 南航 PA3.1
- 对word2vec的一些浅层理解
- 使用U2-Net深层网络实现——证件照生成程序
- IDA中常见快捷键
- Application of OpenGL gllightfv function and related knowledge of light source
猜你喜欢
leetcode-304:二维区域和检索 - 矩阵不可变
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
AHB bus in stm32_ Apb2 bus_ Apb1 bus what are these
5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
P1223 排队接水/1319:【例6.1】排队接水
Some superficial understanding of word2vec
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
基于HPC场景的集群任务调度系统LSF/SGE/Slurm/PBS
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
Weekly recommended short videos: what are the functions of L2 that we often use in daily life?
随机推荐
BigDecimal数值比较
Why is the reflection efficiency low?
根据设备信息进行页面跳转至移动端页面或者PC端页面
关于hzero-resource报错(groovy.lang.MissingPropertyException: No such property: weight for class)
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
[homework] 2022.7.6 write your own cal function
1321:【例6.3】删数问题(Noip1994)
BigDecimal value comparison
[email protected] can help us get the log object quickly
mysql插入数据创建触发器填充uuid字段值
Leetcode-303: region and retrieval - array immutable
Talking about the return format in the log, encapsulation format handling, exception handling
Learning records - high precision addition and multiplication
P2788 数学1(math1)- 加减算式
Slurm资源管理与作业调度系统安装配置
555电路详解
Study summary of postgraduate entrance examination in November
2022.7.3DAY595
嵌入式工程师如何提高工作效率
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!