3D CNN Test Dataset Evaluation
This directory contains all the necessary files and results for evaluating the baseline 3D CNN model on the test dataset.
๐ Overview
The baseline 3D CNN model has been executed on the test dataset with results pre-generated for your reference. This README provides instructions on how to use the scripts and interpret the results.
๐ Directory Structure
.
โโโ format_test_dataset.py # Script to convert MATLAB files to model-compatible format
โโโ test_dataset_summary.py # Script to generate predictions and visualizations
โโโ Test_Dataset_Results/ # Directory containing all output files
โ โโโ [prediction images] # Side-by-side comparisons of predictions and ground truth
โ โโโ test_results.txt # Full console output with evaluation metrics
โโโ pred/
โโโ big_epoch_4_finished.pth # Final trained model checkpoint used for predictions
๐ Using the Scripts
Data Preparation
To convert your own MATLAB data to the required format:
python format_test_dataset.py
This script is configured to work when executed from its current directory within Box.
Generating Predictions
To recreate the evaluation results or run on your own data:
python test_dataset_summary.py
This will:
- Load the model checkpoint (
big_epoch_4_finished.pth)
- Process the test dataset
- Generate predictions
- Save visualization images and performance metrics
๐ Pre-Generated Results
For your convenience, we've already executed the evaluation pipeline:
Prediction Images: Located in Test_Dataset_Results/, these PNG files display the model's predictions side-by-side with the ground truth labels from the corresponding x.npy files.
Performance Metrics: The complete evaluation output has been saved to test_results.txt, including detailed metrics on model performance.
๐ Notes
- All results were generated using the final model checkpoint (
big_epoch_4_finished.pth)
- The pre-generated results are provided to ensure reproducibility and minimize potential issues
- You can rerun any of the scripts on your own data following the instructions above
3D CNN Base Model
A comprehensive implementation of a 3D Convolutional Neural Network (CNN) pipeline for volumetric data processing.
๐ Directory Structure
.
โโโ Preprocessing/
โ โโโ eda-mat.py # Converts raw .mat data into model-compatible format
โโโ train-3dcnn-minibatches.py # Main training script
โโโ 3dcnn-summary.py # Evaluation and visualization script
โโโ checkpoints/
โ โโโ big_epoch_3_finished.pth # Trained model weights after 3 epochs
โโโ Results/
โโโ 3DCNN_results.txt # Full evaluation metrics and console output
โโโ loss_plot.png # Training/validation loss curve
โโโ [prediction images] # Visualization of predictions vs ground truth
๐ Getting Started
Prerequisites
- Python 3.6+
- PyTorch
- NumPy
- Matplotlib
- SciPy (for .mat file handling)
Data Preparation
The processed/ directory (not included in repository due to size constraints) should contain the preprocessed dataset in .npy format. To generate this data:
- Place your raw
.mat files in the appropriate input directory
- Run the preprocessing script:
python Preprocessing/eda-mat.py
Training
To train the 3D CNN model:
python train-3dcnn-minibatches.py
The script will save model checkpoints in the checkpoints/ directory.
Evaluation
To evaluate model performance and generate visualizations:
python 3dcnn-summary.py
This will produce prediction images and performance metrics in the Results/ directory.
๐ Results
Model performance can be assessed through:
- Side-by-side comparison images of predictions vs ground truth
- Complete metrics in
3DCNN_results.txt
- Training/validation loss curves in
loss_plot.png
๐ Notes
- The final model checkpoint (
big_epoch_3_finished.pth) represents the model after 3 full training epochs
- For large datasets, ensure sufficient computational resources are available
- Hyperparameters can be adjusted in the respective training script
3DCNN+ ๐
A modular pipeline for 3D cube regression using Box.com for data storage ๐ฆ and PyTorch ๐ฅ for model training.
Overview ๐
3DCNN+ is a two-part Python project designed for efficient 3D voxel-based regression:
- Data Download (
box.py): Securely fetches preprocessed NumPy data from Box.com using the Box Python SDK.
- Model Training (
cnnp.py): Trains a performant 3D convolutional neural network on the downloaded data.
๐ Table of Contents
Prerequisites โ
Python 3.8+
PyTorch 2.0+
Box SDK
NumPy, Pandas, Matplotlib, tqdm
Install dependencies with:
pip install -r requirements.txt
Setup โ๏ธ
1. Environment Variables
Create a .env file or export these variables before running:
export BOX_CLIENT_ID="your_client_id"
export BOX_CLIENT_SECRET="your_client_secret"
export BOX_DEVELOPER_TOKEN="your_developer_token"
2. Project Folder ID
In box.py, set project1_id to your Box root folder ID.
Part 1: Data Download (box.py) ๐ฆ
This script authenticates with Box.com via OAuth2 and downloads the processed folder containing all required data.
python box.py
Key Functions
| Function |
Description |
get_folder_id_by_name() |
Locates a subfolder ID by name |
download_folder() |
Recursively downloads files and subfolders |
Part 2: Model Training (cnnp.py) ๐๏ธโโ๏ธ
This script handles data loading, model building, and training the 3D CNN.
python cnnp.py
Configuration Options
| Parameter |
Description |
Default |
BATCH_SIZE |
Samples per batch |
64 |
BIG_EPOCHS |
Number of training epochs |
100 |
LEARNING_RATE |
Initial learning rate |
0.001 |
NUM_SAMPLES |
Patches per mini-epoch |
10000 |
Model Architecture: CubeRegressor
Input โ Conv3D โ BatchNorm โ ReLU โ MaxPool3D โ ... โ AdaptiveAvgPool3D โ FC โ Output
Training Features
- Memory Efficiency: Memory-mapped arrays for low RAM usage
- Optimization: Adam optimizer with ReduceLROnPlateau scheduler
- Speed: Mixed precision training with torch.amp
- Monitoring: Automatic checkpointing and loss visualization
How It Works ๐
โโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโ
โ Box.com โ โ โ box.py โ โ โ Local โ โ โ cnnp.py โ
โ Storage โ โ Download โ โ Processed โ โ Training โ
โโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโ
โ Model โ
โ Outputs โ
โโโโโโโโโโโโโ
- Authentication: Secure OAuth2 connection to Box.com
- Data Handling: Memory-mapped NumPy arrays for efficient processing
- Patch Extraction: 4D tensors
(batch, channels, D, H, W) centered on voxels
- Training Strategy: Large batches, sampling, mixed precision, adaptive learning rate
Results ๐
Output Files
- Model Checkpoints:
./checkpoints/epoch_<n>.pth
- Loss Visualization:
./checkpoints/loss_plot.png
Performance Metrics
Example output:
Validation MSE: 0.014
Validation MAE: 0.1098
Validation Rยฒ: -0.1282
License
MIT License
Made with โค๏ธ by your favorite ML group
</div