Recently Kaggle released the RSNA 2023 Abdominal Trauma Detection Abdominal Trauma Detection Competition. This competition is a computer vision task .
Competitors were required to identify the type and extent of injury in CT scans of trauma patients. The competition will evaluate the mean of the sample-weighted log loss for each injury type in the submitted data, and any iniury injury predictions generated by this metric .
In order to help students score and win cards, I joined hands with Mr. Mozak, a top 1000 Kaggle master, to give a lecture on the competition questions and explain the high score baseline in detail . The course is worth 198 yuan, and it is free to watch for a limited time ! Scan the QR code to unlock immediately!
Scan code to add course consultant
The lectures on the competition questions are free to watch, and the high score baseline is explained in detail!
The idea of this game is:
Data preprocessing and image feature extraction
Use a Python library such as pydicom to load these images. Since DICOM data may contain multiple image sequences, they can be organized according to patient_id and series_id.
model selection
You can choose to use classic convolutional neural network architectures such as ResNet, DenseNet or EfficientNet.
Model Training and Validation
Split the data into training and validation sets for training and tuning the model.
Model inference and test set evaluation
Perform inference on the trained model to make predictions on images in the test set.
Scan code to add course consultant
The lectures on the competition questions are free to watch, and the high-score baseline is explained in detail !The following are some key codes:
convert DICOM to 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)
Load the base model
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)
model prediction
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)
Scan code to add course consultant
The lectures on the competition questions are free to watch, and the high-score baseline is explained in detail !