医学心脏数据集分割建模实战
1.数据集
下载链接:需要在:EchoNet Dynamic 进行申请,源码也是由斯坦福公布的
数据集为心脏跳动的视频,我们可以根据视频中的图像,对每一帧的图像进行图像分割,根据心脏跳动时心房或者心室面积的变化,协助诊断。
2.分割任务流程解读
整段代码比较简单,模型都是使用的pytorch提供的模型,这篇研究的价值在于探究了深度学习应用的领域,提出了一个数据集
echonet/utils/segmentation.py
配置参数解读
Args:num_epochs (int, optional): Number of epochs during trainingDefaults to 50.迭代次数modelname (str, optional): Name of segmentation model. One of ``deeplabv3_resnet50'', ``deeplabv3_resnet101'', ``fcn_resnet50'', or ``fcn_resnet101'' 模型名称,主要为pytorch内置模型pretrained (bool, optional): Whether to use pretrained weights for modelDefaults to False.加载预训练权重output (str or None, optional): 输出文件位置device (str or None, optional): 设备(CPU/GPU))n_train_patients (str or None, optional): 提前停止策略num_workers (int, optional): 线程数batch_size (int, optional): 一个批次的大小seed (int, optional):随机种子lr_step_period (int or None, optional): 学习率衰减save_segmentation (bool, optional): 保存分割结果block_size (int, optional): 视频太长的话,需不需要考虑分块保存run_test (bool, optional): 进行测试
任务流程:
- 选择随机种子、输出文件保存位置、以及设备(CPU/GPU)
- 模型:从pytorch中加载模型,其中输出层需要进行修改,输出需要改为1,即即心房/非心房,以预测概率值
- 选择优化器,求出图像的均值和标准差,以方便对图像进行归一化处理
- 读取数据,读取视频数据,同时标签文件是包含视频名称/帧、多边形mask、数据集划分等组成,需要生成mask。
- 然后开始训练,并统计相关指标
def run_epoch(model, dataloader, train, optim, device):"""Run one epoch of training/evaluation for segmentation.Args:model (torch.nn.Module): Model to train/evaulate.dataloder (torch.utils.data.DataLoader): Dataloader for dataset.train (bool): Whether or not to train model.optim (torch.optim.Optimizer): Optimizerdevice (torch.device): Device to run on"""total = 0.n = 0pos = 0neg = 0pos_pix = 0neg_pix = 0model.train(train)large_inter = 0large_union = 0small_inter = 0small_union = 0large_inter_list = []large_union_list = []small_inter_list = []small_union_list = []with torch.set_grad_enabled(train):with tqdm.tqdm(total=len(dataloader)) as pbar:for (_, (large_frame, small_frame, large_trace, small_trace)) in dataloader:# Count number of pixels in/out of human segmentationpos += (large_trace == 1).sum().item()pos += (small_trace == 1).sum().item()neg += (large_trace == 0).sum().item()neg += (small_trace == 0).sum().item()# Count number of pixels in/out of computer segmentationpos_pix += (large_trace == 1).sum(0).to("cpu").detach().numpy()pos_pix += (small_trace == 1).sum(0).to("cpu").detach().numpy()neg_pix += (large_trace == 0).sum(0).to("cpu").detach().numpy()neg_pix += (small_trace == 0).sum(0).to("cpu").detach().numpy()# Run prediction for diastolic frames and compute losslarge_frame = large_frame.to(device)large_trace = large_trace.to(device)y_large = model(large_frame)["out"]loss_large = torch.nn.functional.binary_cross_entropy_with_logits(y_large[:, 0, :, :], large_trace, reduction="sum")# Compute pixel intersection and union between human and computer segmentationslarge_inter += np.logical_and(y_large[:, 0, :, :].detach().cpu().numpy() > 0., large_trace[:, :, :].detach().cpu().numpy() > 0.).sum()large_union += np.logical_or(y_large[:, 0, :, :].detach().cpu().numpy() > 0., large_trace[:, :, :].detach().cpu().numpy() > 0.).sum()large_inter_list.extend(np.logical_and(y_large[:, 0, :, :].detach().cpu().numpy() > 0., large_trace[:, :, :].detach().cpu().numpy() > 0.).sum((1, 2)))large_union_list.extend(np.logical_or(y_large[:, 0, :, :].detach().cpu().numpy() > 0., large_trace[:, :, :].detach().cpu().numpy() > 0.).sum((1, 2)))# Run prediction for systolic frames and compute losssmall_frame = small_frame.to(device)small_trace = small_trace.to(device)y_small = model(small_frame)["out"]loss_small = torch.nn.functional.binary_cross_entropy_with_logits(y_small[:, 0, :, :], small_trace, reduction="sum")# Compute pixel intersection and union between human and computer segmentationssmall_inter += np.logical_and(y_small[:, 0, :, :].detach().cpu().numpy() > 0., small_trace[:, :, :].detach().cpu().numpy() > 0.).sum()small_union += np.logical_or(y_small[:, 0, :, :].detach().cpu().numpy() > 0., small_trace[:, :, :].detach().cpu().numpy() > 0.).sum()small_inter_list.extend(np.logical_and(y_small[:, 0, :, :].detach().cpu().numpy() > 0., small_trace[:, :, :].detach().cpu().numpy() > 0.).sum((1, 2)))small_union_list.extend(np.logical_or(y_small[:, 0, :, :].detach().cpu().numpy() > 0., small_trace[:, :, :].detach().cpu().numpy() > 0.).sum((1, 2)))# Take gradient step if trainingloss = (loss_large + loss_small) / 2if train:optim.zero_grad()loss.backward()optim.step()# Accumulate losses and compute baselinestotal += loss.item()n += large_trace.size(0)p = pos / (pos + neg)p_pix = (pos_pix + 1) / (pos_pix + neg_pix + 2)# Show info on process barpbar.set_postfix_str("{:.4f} ({:.4f}) / {:.4f} {:.4f}, {:.4f}, {:.4f}".format(total / n / 112 / 112, loss.item() / large_trace.size(0) / 112 / 112, -p * math.log(p) - (1 - p) * math.log(1 - p), (-p_pix * np.log(p_pix) - (1 - p_pix) * np.log(1 - p_pix)).mean(), 2 * large_inter / (large_union + large_inter), 2 * small_inter / (small_union + small_inter)))pbar.update()large_inter_list = np.array(large_inter_list)large_union_list = np.array(large_union_list)small_inter_list = np.array(small_inter_list)small_union_list = np.array(small_union_list)return (total / n / 112 / 112,large_inter_list,large_union_list,small_inter_list,small_union_list,)
医学心脏数据集分割建模实战相关推荐
- 深度学习实战39-U-Net模型在医学影像识别分割上的应用技巧,以细胞核分割任务为例
大家好,我是微学AI,今天给大家介绍一下深度学习实战39-U-Net模型在医学影像识别分割上的应用技巧,以细胞核分割任务为例.本文将介绍在医学影像分割领域中应用U-Net模型的方法.我们将从U-Net ...
- 上海交大发布 MedMNIST 医学图像分析数据集 新基准
来源 | HyperAI超神经 责编 | 晋兆雨 头图 | 付费下载于视觉中国 内容概要:医学图像分析是一个非常复杂的跨学科领域,近日上海交通大学发布了 MedMNIST 数据集,有望促进医学图像分析 ...
- 【深度学习】上海交大发布 MedMNIST 医学图像分析数据集 新基准
By 超神经 内容概要:医学图像分析是一个非常复杂的跨学科领域,近日上海交通大学发布了 MedMNIST 数据集,有望促进医学图像分析的发展. 关键词:医学图像分析 公开数据集 令人头秃的医学图 ...
- 图像处理基本库的学习笔记5--公共数据集,PASCAL VOC数据集,NYUD V2数据集的简介与提取,COCO2017,医学影像数据集汇总
目录 公共数据集 计算机视觉标准数据集整理-PASCAL VOC数据集 数据集文件结构 Annotation JPEGImages SegmentationClass SegmentationObje ...
- 《Python金融大数据风控建模实战》 第6章 变量分箱方法
<Python金融大数据风控建模实战> 第6章 变量分箱方法 本章引言 Python代码实现及注释 本章引言 变量分箱是一种特征工程方法,意在增强变量的可解释性与预测能力.变量分箱方法主要 ...
- brats数据集以及其他的医学影像数据集
脑肿瘤分割(BraTS)挑战集中于评估在多参数磁共振成像(mpMRI)扫描中分割脑肿瘤的最新方法.自成立以来,它的主要作用有两个方面:a)公开可用的数据集和b)公共基准.BraTS利用多机构术前mpM ...
- 【语义分割项目实战】Augmentor数据增强与U-Net的综合应用
之前已经介绍过了数据增强工具Augmentor的使用 [语义分割项目实战]基于Augmentor工具的语义分割中常见几种数据增强方式(一)_Bill-QAQ-的博客-CSDN博客 以及简单的复现U-N ...
- 100+医学影像数据集集锦
医学影像数据集集锦 前言 本项目的目标是整理一个医学影像方向数据集的列表,提供每个数据集的基本信息,并对其中License允许的提供不限速下载.项目按照数据集关注的器官对其进行分类.需要整理的数据集很 ...
- 白话Elasticsearch60-数据建模实战_Join datatype 父子关系数据建模
文章目录 概述 官网 示例 概述 继续跟中华石杉老师学习ES,第60篇 课程地址: https://www.roncoo.com/view/55 白话Elasticsearch58-数据建模实战_基于 ...
最新文章
- IO异常 java.net.SocketException: Connection reset
- jQuery操作input
- 让你的名字在百度排名前列
- 14-Providing protection for complex software
- ASP.NET MVC随想录——漫谈OWIN
- 和一个刚毕业不久的朋友聊天
- SqlMap异常的处理
- haproxy安装_Haproxy负载mycat集群配置
- nginx匹配规则说明以及匹配的优先级
- 中兴机顶盒刷机后服务器连接失败,刷机后rec无法进入!!!求助
- 明解c语言答案第八章,《明解C语言》第1章初识C语言练习题答案(最新整理)
- Delta3d 2.8 版本终于发版
- CentOS7 安装Samba
- 用户体验是什么?如何把用户体验做到极致, 这里有答案
- 超详细版-计算网络地址、子网、广播地址、主机数
- 1.(group by)如何让group by分组后,每组中的所有数据都显示出来
- 35岁的程序员:第43章,职级评定
- android logcat 包名过滤日志
- 接口压力测试脚本编写
- 再见了数仓开发!我选有钱有话语权的大数据架构师!