# Explainable MRI-Based Ensemble Learnable Architecture for Alzheimer's Disease Detection
## 3 Methodology
``` Convolutional Layers: Apply a sequence of Conv2D layers with increasing filter counts: \(\bullet\) Conv2D(filters = 32, kernel_size = 3 \(\times\) 3, activation ='relu') \(\bullet\) Conv2D(filters = 64, kernel_size = 3 \(\times\) 3, activation ='relu') \(\bullet\) Conv2D(filters = 128, kernel_size = 3 \(\times\) 3, activation ='relu') \(\bullet\) Conv2D(filters = 256, kernel_size = 3 \(\times\) 3, activation ='relu') \(\bullet\) Conv2D(filters = 512, kernel_size = 3 \(\times\) 3, activation ='relu') \(\bullet\) Conv2D(filters = 1024, kernel_size = 3 \(\times\) 3, activation ='relu')  MaxPooling Layers: After each convolution or set of convolutions: \(\bullet\) Apply MaxPooling2D(pool_size = 2 \(\times\) 2) six times, respectively \(\bullet\) This reduces spatial dimensions while preserving important features  Flatten Operation: \(\bullet\) Flatten the output of the last MaxPooling layer \(\bullet\) Convert 3D feature maps to a 1D feature vector Dense Layers with ReLU: Apply four fully connected layers with decreasing neuron counts: \(\bullet\) Dense(units = 512, activation ='relu') \(\bullet\) Dense(units = 512, activation ='relu') \(\bullet\) Dense(units = 256, activation ='relu') \(\bullet\) Dense(units = 128, activation ='relu') Dropout: \(\bullet\) Apply Dropout(rate = 0.5) \(\bullet\) This prevents overfitting by randomly deactivating 50% of neurons during training Softmax Layer: \(\bullet\) Dense(units = num_classes, activation ='softmax') Outputs probability distribution over classes```
1:Base Model Selection: Choose from two categories of pretrained models
2:Category 1: Fully Frozen Models
* MobileNetV2: Initialize with ImageNet weights, include_top = False
* VGG19: Initialize with ImageNet weights, include_top = False
* Freeze all layers in these models (layer.trainable = False)
3:Category 2: Partially Unfrozen Models
* ResNet50: Initialize with ImageNet weights, include_top = False
* EfficientNetB0: Initialize with ImageNet weights, include_top = False
* DenseNet201: Initialize with ImageNet weights, include_top = False
* Freeze all layers except the last 20 (layer.trainable = False for layer in base_model.layers[:-20])
4:Feature Extraction:
* Apply Global Average Pooling 2D to the base model output
* x = GlobalAveragePooling2D(0(base_model.output)
5:Model-Specific Dense Layers:
* Dense(4096, activation ='relu')
- Dense(2048, activation ='relu')
- Dense(1024, activation ='relu')
- Dense(512, activation ='relu')
- Dense(256, activation ='relu')
* Dense(1024, activation ='relu')
- Dense(512, activation ='relu')
6:Regularization Techniques: * For ResNet50, MobileNetV2: - Apply Dropout after each Dense layer (rates: 0.5, 0.5, 0.3) * For EfficientNetB0, DenseNet201: - Apply BatchNormalization + Dropout after each Dense layer - Dropout rates: 0.5, 0.5, 0.3 * For VGG19: - Apply BatchNormalization + Dropout after each Dense layer - Dropout rates: 0.5 for first four layers, 0.3 for the last layer
7:Classification Layer: * Final Dense layer with softmax activation: Dense(num_classes, activation ='softmax')
8:Optimization: * Adam optimizer with learning rate \(1\times 10^{-4}\) (for ResNet50, EfficientNetB0, DenseNet201) * Default Adam optimizer (for MobileNetV2, VGG19) * Loss function: sparse_categorical_crossentropy * Metric: accuracy
9:Training Strategy: * Multi-GPU training with tf.distribute.MirroredStrategy() * Early stopping (patience = 3) monitoring validation metrics * Model checkpoint to save best weights * Maximum 1000 epochs with validation after each epoch
```
1:Pre-trained ViT Model: * Use ViT_B16 pre-trained on ImageNet (pretrained = True) * Configure for input size of 224 \(\times\) 224 pixels * Remove classification head (include_top = False)
2:Fine-tuning Strategy: * Freze all layers except the last 10 layers for fine-tuning * layer.trainable = False for layer in vit_model.layers[:-10]
3:Transformer Architecture: (Embedded in pre-trained model)
4:Patch Embedding: Divide input into fixed-size patches
5:Position Embedding: Add learnable position encodings
6:Transformer Encoder: Multiple self-attention blocks - Multi-Head Self-Attention (MSA) - MLP blocks with residual connections - Layer Normalization
7:[CLS] Token: Special token for classification
8:Custom Classification Head: * Layer Normalization: LayerNorm(epsslon = 1 \(\times\) 10\({}^{-6}\)) * Dense Layer 1: Dense(1024, activation ='relu', kernel_regularizer = l2(0.001)) * Batch Normalization: BatchNormalization() * Dropout Dropout(0.5) * Dense Layer 2: Dense(512, activation ='relu')
9:Batch Normalization: BatchNormalization() * Dropout Dropout(0.5) * Output Layer: Dense(num_classes, activation ='softmax')
10:Optimization: * Optimizer: AdamW with initial_learning_rate = 1 \(\times\) 10\({}^{-4}\) * Loss Function: sparse_categorical_crossentropy * Metrics accuracy
11:Learning Rate Strategy: * Reduce learning rate when validation loss plateaus * ReduceLROnPlateau(monitor = 'val_loss', factor = 0.5, patience = 5)
12:Training Strategy: * Multi-GPU training with tf.distribute.MirroredStrategy() * Early stopping with patience = 3, monitoring validation accuracy * Model checkpoint to save best weights * Maximum 1000 epochs with validation after each epoch
```  
**Algorithm 4** Vision Transformer (ViT) for MRI classification