Automated tumor detection and segmentation from MRI scans using a U-Net convolutional architecture trained on brain tumor datasets.
Interactive Demo
Upload a brain MRI image to visualize the segmentation process. The demo shows how the model identifies and highlights tumor regions.
Methodology
MRI brain scans sourced from Kaggle's Brain Tumor Segmentation dataset. Images include paired grayscale masks marking tumor boundaries.
Kaggle DatasetImages are loaded, cropped to region of interest (rows 90–450, cols 150–406), resized to 256×256, and normalized to [0,1]. Masks converted to binary boolean arrays.
NumPy · TensorFlow5-block encoder–decoder with skip connections. Adam optimizer, binary cross-entropy loss. EarlyStopping with patience=2 prevents overfitting. 10% validation split.
Keras · EarlyStoppingModel outputs a sigmoid probability mask. Predictions visualized as standalone mask and alpha-blended overlay on the original scan.
Matplotlib · cv2Model Design
Encoder–decoder with skip connections enabling precise spatial localization.
5 levels: 16→32→64→128→256 filters. Each block has 2× Conv2D (3×3, ReLU) + Dropout + MaxPooling. Progressively captures abstract features.
Conv2DTranspose upsamples feature maps. Concatenated with encoder skip connections to recover fine spatial details lost during pooling.
Direct connections from encoder to decoder at each level. Ensures high-resolution spatial information is preserved for precise segmentation boundaries.
1×1 Conv2D with sigmoid activation produces a single-channel probability map. Threshold at 0.5 for binary tumor/non-tumor classification.
# U-Net Output Head outputs = tf.keras.layers.Conv2D(1, (1, 1), activation='sigmoid')(c9) model = tf.keras.Model(inputs=[inputs], outputs=[outputs]) model.compile( optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'] ) # Training with EarlyStopping history = model.fit( X_train, y_train, validation_split=0.1, batch_size=32, epochs=5, callbacks=[EarlyStopping(monitor='val_loss', patience=2)] )