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


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


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


扫码添加课程顾问

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


本次比赛的思路为:


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

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

模型选择

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

模型训练和验证

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

模型推断和测试集评估

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


扫码添加课程顾问

赛题讲座免费看,详解高分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)


扫码添加课程顾问

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


内容中包含的图片若涉及版权问题,请及时与我们联系删除