FloodNet is a semantic segmentation project designed to identify flooded and non-flooded regions in aerial imagery. The project uses deep learning techniques based on the DeepLabV3+ architecture using TensorFlow and Keras. to classify each pixel in an image into predefined categories (e.g., water, Tree, Vehicle).
This notebook implements the end-to-end pipeline for:
- An EfficientNetV2-S backbone pretrained on ImageNet for feature extraction.
- Dilated Spatial Pyramid Pooling (ASPP) for capturing multiscale context.
- A custom decoder to upsample features to the input image resolution.
- Preparing and preprocessing data.
- Training and validating the segmentation model.
- Evaluating performance metrics (e.g., Dice Coefficient, IoU).
- Performing inference on test images with visualized outputs.
The dataset includes 10 classes, each representing different features in flood-affected areas:
Class ID | Class Name |
---|---|
0 | Background |
1 | Building Flooded |
2 | Building Non-Flooded |
3 | Road Flooded |
4 | Road Non-Flooded |
5 | Water |
6 | Tree |
7 | Vehicle |
8 | Pool |
9 | Grass |
The model accepts images of a specific shape (shape) defined during initialization. The input layer:
model_input = Input(shape=shape)
ensures compatibility with the EfficientNetV2 backbone.
EfficientNetV2-S is employed for extracting hierarchical feature maps:
backbone = tf.keras.applications.EfficientNetV2S(include_top=False, weights="imagenet", input_tensor=model_input)
backbone.trainable = True
The backbone's key feature maps are accessed for multiscale processing:
- block6b_expand_activation (smallest spatial resolution, richest features)
- block4b_expand_activation
- block3b_expand_activation
- block2b_expand_activation (largest spatial resolution)
For multiscale context, the ASPP block processes outputs from deeper layers:
input_a = DilatedSpatialPyramidPooling(input_a, num_filters=256)
Each ASPP block includes parallel dilated convolutions with varying dilation rates.
Outputs from the ASPP and other backbone layers are upsampled to match the desired resolution:
input_a = UpSampling2D(size=(16, 16), interpolation="bilinear")(input_a)
The last layer applies a 1x1 convolution and softmax activation:
outputs = Conv2D(num_classes, kernel_size=(1, 1), padding="valid", activation="softmax")(x)
This generates a segmentation map with probabilities across all classes.
- Epochs: 40
- Batch Size: 2
- Optimizer: AdamW with initial learning rate of 1e-3 and weight decay of 1e-5
- Learning Rate Scheduler: ReduceLROnPlate
- Dice Coefficient: Measures overlap between predicted and true masks.
- Intersection over Union (IoU): Computes pixel-wise intersection vs union for each class.
![Screenshot 2024-11-14 at 10 45 59 am](https://private-user-images.githubusercontent.com/68953368/386160511-4ddeaa5f-16ec-4109-a1a7-e77cca8de1f7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODE0NjUsIm5iZiI6MTczOTQ4MTE2NSwicGF0aCI6Ii82ODk1MzM2OC8zODYxNjA1MTEtNGRkZWFhNWYtMTZlYy00MTA5LWExYTctZTc3Y2NhOGRlMWY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDIxMTI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM0MDE5NTgxOTEwZjU4NjMwNDMyNGY0YmVkYjcyNGU4OTA3NWNmMDIzZjU5ODA1Njg3YWFjMTZhZTNmNzQxZjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.V-cRGjhZjnk6heCX6eRCvs00LOpc8khlsRPmUWT7ACI)
![prediction](https://private-user-images.githubusercontent.com/68953368/390592914-0bbc681b-59ed-4f1a-8418-e8c944b6f633.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODE0NjUsIm5iZiI6MTczOTQ4MTE2NSwicGF0aCI6Ii82ODk1MzM2OC8zOTA1OTI5MTQtMGJiYzY4MWItNTllZC00ZjFhLTg0MTgtZThjOTQ0YjZmNjMzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDIxMTI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY3Yjg5MWMwMjBkODJlZjVkODM5MmU5ZDYxNzUzZmVmNzg4MmYwNTQwNmUwNzkwNmIyYzcxZDJhOTgxMDE0NDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.XUqov_5AAppon2yEe4RO0bDBuETKI3wvigtIi-FXvp8)
![Screenshot 2024-11-14 at 10 48 14 am](https://private-user-images.githubusercontent.com/68953368/386161300-8c9a7280-e945-483f-bbaf-7434fb51980f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODE0NjUsIm5iZiI6MTczOTQ4MTE2NSwicGF0aCI6Ii82ODk1MzM2OC8zODYxNjEzMDAtOGM5YTcyODAtZTk0NS00ODNmLWJiYWYtNzQzNGZiNTE5ODBmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDIxMTI0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRhY2QxMzc4ZGE5ZjRhNjI0ZTM3NTliMjcwYjdkNDcxYTVlMmNhOWY1MjczOGZkMWE0NGVjNzI3ZDA5ZDhkZjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.FBigtNmdd_GITTRBWqC8uKuULVESBs1XCXIS1AE5OXs)