Memuat
Memuat
Watch every step above performed live, with English narration.
0 plays
Class book
Page 1 / 8
Cover: Class U-Net Brain Tumor Segmentation #1: Brain MRI Dataset & Tumor Mask: Loading, Visualization & Patient-wise Split
Click a page or use ◀ ▶ to turn · swipe on mobile · to enlarge
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class U-Net Brain Tumor Segmentation #1: Brain MRI Dataset & Tumor Mask: Loading, Visualization & Patient-wise Splitting”.
Other ways we can help with Python.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Multi-Objective Optimization Course: NSGA-II, MOPSO & Hybrid Algorithms (Python)

ECG Arrhythmia Classification Course with Wavelet & Deep Learning (PyTorch)

ANFIS + PSO/GA Course for Non-Linear Time Series Forecasting (Python)
Have it built for you
No time to learn Python? Our team can do the project for you.

Python Machine Learning — Prediction Models, Customer Segmentation, Fraud Detection & AI Apps

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
This is the final result, MRI brain images from 110 patients, complete with tumor masks drawn by doctors, and yellow lines marking the tumor boundaries on top of the images. This is the first step of our series in building a metaheuristic optimized U-Net for brain tumor segmentation. Let's get started. Welcome to the AI research tutorial series, brain tumor image segmentation with a metaheuristic optimized U-Net. Unlike classification, which only answers whether there is a tumor or not, segmentation marks which pixels are part of the tumor, so doctors know the location and size. In this 6-episode series, we will discuss the MRI dataset, preprocessing and augmentation, building the U-Net from scratch, Dice loss and IOU, hyperparameter optimization with particle swarm optimization and gray wolf optimizer, all the way to evaluation. In this first episode, we will get to know the data.
We open the terminal through the terminal menu, new terminal, then install the required libraries, torque, open python, scikit-learn, and matplotlib. The dataset is LGGMRI segmentation from RSIB TCGA, MRI brain images of 110 patients with low-grade glioma, with manually drawn tumor masks. We have already downsized it to 128 pixels in the dataset folder, one subfolder per patient. This folder is available in the customer's premium project file.
Create a file named data_underscore_brain_dot_py. The load_patient function reads all MRI slices of a patient along with their mask, then resizes them to 96 pixels. Note that the images are downsized with bilinear interpolation, while the mask uses nearest neighbor interpolation so that the values remain 0 or 1. The load_all function combines all patients and saves the compressed CNPZ files, so that the next loading is much faster. The most important function is the split_patient function. The data is split into 70, 15, 15 percent based on patients, not on slices.
Now create the file exploration_underscore_brain_dot_py and run it. There are 110 patients with a total of 3,929 slices. Each image is 96x96 with 3 channels, which are 3 MRI sequences: pre-contrast, flair, and post-contrast. The mask only contains 0 and 1.
Let's count how many slices contain a tumor. Only 1,373 slices, about 35 percent. And among the tumor-containing slices, the average tumor area is only 2.9 percent of the image. This is the main challenge of medical segmentation, the tumor pixels are very few compared to the background. A model that always predicts no tumor will appear accurate pixel-wise, although it is not useful. Therefore, we will use the DAIS and IOU metrics later. Look at the data split.
77 patients for training, 16 for validation, and 17 for testing. Why per patient? Slices from the same patient are very similar. If split by slice, the model seems to see exam questions while studying, and the score becomes overly optimistic. This is a common mistake found in descriptions, so make sure your data split is per patient.
Now, visualization. The first row is the MRI image, the second row is the tumor mask in white, and the third row is the overlay, with a yellow line marking the tumor boundary over the image. The tumor appears as a bright area in the flair sequence, with highly variable shapes and sizes. This boundary line is what UNET will later need to draw. Finally, two graphs: the number of slices without and with tumors, and a histogram of tumor area.
Most tumors occupy less than 5% of the image, only a few are large. This distribution needs to be remembered when reading evaluation results, since small tumors are much harder to segment.
Done. We have now become familiar with the LGGMRI dataset, loaded images and masks per patient, understood the tumor pixel imbalance, and split the data without leakage. In the next episode, we will perform MRI preprocessing and image augmentation along with the mask. Currently working on a thesis, dissertation, or AI research in the field of medical image segmentation? Cerdas Inovasi Digital helps with deep learning implementation, from UNET segmentation, metaheuristic optimization with PSO and Grey Wolf, up to DAIS, IOU evaluation, result writing, and opening deep learning courses with PyTorch. Want to master the entire series, from brain MRI datasets to optimized UNET? All 6 episodes, complete with step-by-step PDF guides and source code, are available for premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or pay once Rp999.000 for lifetime access. Want just one class? Buy single class with lifetime access. Subscribe now on the premium page at cerdasinovasidigital.com Contact our WhatsApp or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →