Kaggle医学影像新赛事:腹部创伤检测

c17ce9f898e19aae4e46811652df2237.png

最近Kaggle发布了RSNA 2023 Abdominal Trauma Detection 腹部创伤检测竞赛。本次竞赛是一个计算机视觉任务

参赛者需要在创伤患者的CT扫描中识别出损伤类型及程度。本次比赛将评估提交数据中的每种伤害类型的样本加权对数损失的平均值,及该指标生成的any iniury伤害预测值。

为了帮助同学们冲分拿牌,我联合Kaggle前1000大神Mozak老师,带来赛题讲座,详解高分baseline。课程价值198元,限时免费观看扫码即刻解锁!

1b10559d428015d9030b6ee87fe0a997.png

扫码添加课程顾问

赛题讲座免费看,详解高分baseline!

本次比赛的思路为:

数据预处理和图像特征提取

使用Python库如pydicom来加载这些图像。由于DICOM数据可能包含多个图像序列,可以根据patient_id和series_id将它们组织起来。

模型选择

可以选择使用经典的卷积神经网络架构,如ResNet、DenseNet或EfficientNet。

模型训练和验证

将数据分为训练集和验证集,用于训练和调整模型。

模型推断和测试集评估

在训练好的模型上进行推断,对测试集中的图像进行预测。

60d2588a52690b02062e491a557bbd81.png

扫码添加课程顾问

赛题讲座免费看,详解高分baseline

以下为部分关键代码:

 将DICOM转换为jpg

def dicom_to_image(dicom_image):
    """
    Read the dicom file and preprocess appropriately.
    """
    pixel_array = dicom_image.pixel_array
    
    if dicom_image.PixelRepresentation == 1:
        bit_shift = dicom_image.BitsAllocated - dicom_image.BitsStored
        dtype = pixel_array.dtype 
        new_array = (pixel_array << bit_shift).astype(dtype) >>  bit_shift
        pixel_array = pydicom.pixel_data_handlers.util.apply_modality_lut(new_array, dicom_image)
    
    if dicom_image.PhotometricInterpretation == "MONOCHROME1":
        pixel_array = 1 - pixel_array
    
    # transform to hounsfield units
    intercept = dicom_image.RescaleIntercept
    slope = dicom_image.RescaleSlope
    pixel_array = pixel_array * slope + intercept
    
    # windowing
    window_center = int(dicom_image.WindowCenter)
    window_width = int(dicom_image.WindowWidth)
    img_min = window_center - window_width // 2
    img_max = window_center + window_width // 2
    pixel_array = pixel_array.copy()
    pixel_array[pixel_array < img_min] = img_min
    pixel_array[pixel_array > img_max] = img_max
    
    # normalization
    pixel_array = (pixel_array - pixel_array.min())/(pixel_array.max() - pixel_array.min())
    
    return (pixel_array * 255).astype(np.uint8)

 加载基础模型

model = torchvision.models.resnet34(True)
model.fc = torch.nn.Linear(512, 14)
model.conv1 = nn.Conv2d(1, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)


model = model.cuda()
pos_weight = torch.Tensor([1,2,1,6,1,2,4,1,2,4,1,2,4,6]).cuda()
criterion = nn.BCEWithLogitsLoss(pos_weight=pos_weight)
optimizer = torch.optim.SGD(model.parameters(), 0.0001)

 模型预测

pred_list = []
for pid in train_pids[:10]:    
    pid_paths_dcm_paths = glob.glob('/kaggle/input/rsna-2023-abdominal-trauma-detection/train_images/' + str(pid) + '/*/*')
    pid_paths_dcm_paths.sort()
    
    pid_paths_dcm_paths = pid_paths_dcm_paths[-5:]
    imgs = [Image.fromarray(dicom_to_image(pydicom.read_file(x))) for x in pid_paths_dcm_paths]
    imgs = [transform(x) for x in imgs]
    
    imgs = torch.cat(imgs, 0)
    imgs = imgs[:, None, :, :]
    with torch.no_grad():
        imgs = imgs.cuda()
        output = model(imgs)[:, :-1]
        pred = torch.sigmoid(output).data.cpu().numpy().round(3)
        pred = pred.mean(0)
        
    pred_list.append(pred)

69b5fad9a76f4cf6dd517f7b92a29993.png

扫码添加课程顾问

赛题讲座免费看,详解高分baseline

1b067667e37500cc543e8435ec37ba22.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值