Skip to main content
. 2026 Jan 28;13(2):157. doi: 10.3390/bioengineering13020157
Algorithm 1: Brain Tumor Classification using ConvNeXT Model
Input:
 • Brain MRI dataset (images and labels)
 • Batch size
 • Training epochs
Output:
 • Tumor class label C ∈ {Glioma, Meningioma, Pituitary, No_tumor}
 • Performance metrics
// Step 1: Dataset Loading and Preprocessing
  • (1)

    Load MRI images using image_dataset_from_directory.

  • (2)

    Apply dataset transformations: resize images to 224 × 224, convert to tensors, normalize using ImageNet statistics and augment using on-the-fly.

  • (3)
    Split the dataset into:
    • ○
      80% training
    • ○
      20% validation
  • (4)

    Prefetch all datasets for performance optimization.

// Step 2: Model Initialization
  • (5)

    Import the ConvNeXt Base model pre-trained on ImageNet.

  • (6)

    Replace its classifier head with a new linear layer to output four classes.

// Step 3: Training Setup
  • (7)

    Define the loss function as cross-entropy loss.

  • (8)

    Initialize the optimizer (Adam) with a learning rate of 1 × 10−4.

  • (9)

    Move the model and data to the GPU if available.

// Step 4: Training Loop
  • (10)

    For each epoch:

  • (11)

    Set the model to training mode.

  • (12)

    For each batch in the training set:

  • (13)

    Forward propagate input images through the model.

  • (14)

    Calculate the loss.

  • (15)

    Backpropagate gradients and update model weights.

  • (16)

    Calculate epoch training loss and accuracy.

// Step 5: Validation Loop
  • (17)

    Set the model to evaluation mode.

  • (18)

    For each batch in the validation set:

  • (19)

    Forward propagate validation images, record loss, and predictions.

  • (20)

    Compute validation loss and accuracy.

// Step 6: Benchmarking and Explainability
  • (21)

    Calculate accuracy, precision, recall, F1-score, AUC, Kappa

  • (22)

    Measure and record inference speed (FPS), model size (MB), GPU/CPU memory footprint, and power consumption.

  • (23)

    Apply Grad-CAM++ and gradient SHAP for model interpretation.

// Final Classification
  • (24)

    Apply SoftMax classifier → C

  • (25)
    Return:
    • ○
      Final tumor class C
    • ○
      Performance metrics
    • ○
      Visual overlays