Skip to content

About

Microwave Imaging ML uses machine learning, autoencoders, and neural networks to reconstruct electromagnetic images from S-parameters and scattered fields, enabling non-invasive monitoring, permittivity estimation, and advanced material characterization.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Microwave Imaging with Machine Learning

Processing demo

Fig 0: Microwave Imaging Architecture

Project Overview

This project leverages machine learning to advance microwave imaging, a non-invasive technique for visualizing objects using microwave sensor data. By employing Variational Autoencoders (VAEs), the system reconstructs high-quality images from microwave sensor measurements, enabling applications in fields like medical imaging, security screening, and material characterization. The project processes paired datasets of images (representing objects like crosses, disks, and squares) and corresponding microwave sensor data to learn a shared latent representation, allowing accurate image generation from sensor inputs.

The primary objectives are:

  • To develop a robust pipeline for preprocessing microwave sensor data and corresponding images.
  • To train a VAE-based model that learns to encode and reconstruct images.
  • To map sensor data to the same latent space as images, enabling image reconstruction from sensor measurements.
  • To evaluate the quality of reconstructed images and optimize for real-world applicability.

Motivation

Microwave imaging offers advantages over traditional imaging methods, such as X-rays, due to its non-ionizing nature and ability to penetrate certain materials. However, reconstructing clear images from microwave sensor data is challenging due to the complexity of the data (e.g., complex-valued measurements). This project addresses this challenge by using deep learning to bridge the gap between sensor data and visual representations, achieving high-fidelity image reconstructions.

Methodology

The project employs a two-stage machine learning approach:

  1. Image VAE: A Variational Autoencoder is trained to encode grayscale images (128x128 pixels) into a compact latent space and reconstruct them accurately. This model captures the essential features of the images.
  2. Sensor Encoder: A separate encoder maps microwave sensor data (complex-valued, 13x13 matrices with real and imaginary components) to the same latent space as the Image VAE. This allows the system to generate images from sensor data using the Image VAE's decoder.

Dataset

The dataset consists of:

  • Images: Grayscale PNG files of shapes (cross, disk, square) with optional 30-degree rotations, stored in image_Jan_2025/.
  • Sensor Data: CSV files containing complex-valued microwave measurements, stored in csv_together_Jan_2025/. Each CSV corresponds to an image, following a specific naming convention (e.g., TWI_Cross_001.csv).

Data preprocessing includes:

  • Image augmentations (random cropping, flips) to enhance model robustness.
  • Sensor data normalization and augmentation (affine transformations, Gaussian noise) to simulate real-world variability.
  • Caching of processed sensor data to improve training efficiency.

Training Process

  • Stage 1: The Image VAE is trained to reconstruct images, balancing reconstruction quality and latent space regularization.
  • Stage 2: The Sensor Encoder is trained to align sensor data with the Image VAE's latent space, using the pre-trained Image VAE's decoder to generate images.
  • Training progress is monitored through loss curves and periodic image reconstructions, saved for analysis.

Project Structure

microwave-imaging-ml/
├── preprocess.py           # Data loading and preprocessing
├── vae_encoder.py          # Model definitions and training logic
├── models/                 # Directory for saving trained models
├── reconstructions/        # Directory for image VAE reconstructions
├── sensor_reconstructions/ # Directory for sensor-based image reconstructions
└── README.md               # This file

Prerequisites

To run this project, ensure you have the following dependencies installed:

  • Python 3.8+
  • PyTorch
  • torchvision
  • pandas
  • numpy
  • Pillow (PIL)
  • matplotlib

You can install the required packages using:

pip install torch torchvision pandas numpy pillow matplotlib

Setup Instructions

  1. Clone the Repository :
   git clone <repository-url>
   cd microwave-imaging-ml
  1. Prepare the Dataset :
  • Place your dataset in a parent folder (e.g., data/) with the following structure:
    data/
    ├── image_Jan_2025/
    │   ├── cross_image_30_deg_001.png
    │   ├── disk_image_002.png
    │   ├── square_image_30_deg_003.png
    │   └── ...
    ├── csv_together_Jan_2025/
    │   ├── TWI_Cross_001.csv
    │   ├── TWI_Circle_30_deg_002.csv
    │   ├── TWI_Square_003.csv
    │   └── ...
    
  • Images should be PNG files named as <shape>_image[_30_deg]_<index>.png.
  • CSV files should contain sensor data in complex number format and be named as TWI_<Shape>[_30_deg]_<index>.csv.
  1. Directory Setup :
  • Ensure models/, reconstructions/, and sensor_reconstructions/ directories exist. They will be created automatically during training if they don't exist.

Usage

1. Data Preprocessing

The preprocess.py script defines:

  • ImageSensorDataset : A custom PyTorch Dataset class that pairs images with their corresponding sensor data.
  • Data Transformations :
  • Image transformations: Random cropping, horizontal/vertical flips, and conversion to tensors.
  • Sensor data transformations: Random affine transformations, flips, and Gaussian noise addition.
  • Caching : Sensor data is cached as .pt files to speed up loading.

To use the dataset:

from preprocess import ImageSensorDataset
dataset = ImageSensorDataset(parent_folder="data/", cache=True)

2. Model Training

The vae_encoder.py script defines two models and their training procedures:

  • ImageVAE : A convolutional VAE that learns to encode and reconstruct images (128x128 pixels).
  • SensorEncoder : A convolutional encoder that maps sensor data (2x13x13 tensors, representing real and imaginary parts of complex sensor readings) to the latent space of the Image VAE.

To train the models:

from vae_encoder import ImageVAE, SensorEncoder, train_image_vae, train_sensor_encoder
from preprocess import ImageSensorDataset
from torch.utils.data import DataLoader, random_split

# Load dataset
dataset = ImageSensorDataset(parent_folder="data/", cache=True)
train_size = int(0.8 * len(dataset))
val_size = len(dataset) - train_size
train_dataset, val_dataset = random_split(dataset, [train_size, val_size])
train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
val_loader = DataLoader(val_dataset, batch_size=32)

# Train Image VAE
image_vae = ImageVAE(latent_dim=128).to(device)
image_vae = train_image_vae(image_vae, train_loader, val_loader, epochs=50, lr=1e-4)

# Train Sensor Encoder
sensor_encoder = SensorEncoder(latent_dim=128).to(device)
sensor_encoder = train_sensor_encoder(image_vae, sensor_encoder, train_loader, val_loader, epochs=50, lr=1e-3)

3. Inference

To generate an image from sensor data:

from vae_encoder import generate_image_from_sensor
import torch

# Load trained models
image_vae = ImageVAE(latent_dim=128).to(device)
image_vae.load_state_dict(torch.load("models/best_image_vae.pth"))
sensor_encoder = SensorEncoder(latent_dim=128).to(device)
sensor_encoder.load_state_dict(torch.load("models/best_sensor_encoder.pth"))

# Example sensor input (2x13x13 tensor)
sensor_input = torch.tensor(...).float()  # Replace with actual sensor data
generated_image = generate_image_from_sensor(sensor_encoder, image_vae.decoder, sensor_input)

# Save or visualize the generated image
from torchvision.utils import save_image
save_image(generated_image, "generated_image.png")

4. Outputs

  • Model Checkpoints :
  • models/best_image_vae.pth: Best Image VAE model based on validation loss.
  • models/final_image_vae.pth: Final Image VAE model.
  • models/best_sensor_encoder.pth: Best Sensor Encoder model.
  • models/final_sensor_encoder.pth: Final Sensor Encoder model.
  • Reconstructions :
  • reconstructions/recon_epoch_<N>.png: Image VAE reconstructions for each epoch.
  • sensor_reconstructions/recon_epoch_<N>.png: Sensor-based image reconstructions for each epoch.
  • Loss Plots :
  • models/vae_training_loss.png: Training and validation loss for Image VAE.
  • models/sensor_training_loss.png: Training and validation loss for Sensor Encoder.

Model Architecture

Image VAE

  • Encoder :
  • Input: Grayscale images (1x128x128)
  • Layers: Four convolutional layers (1→32→64→128→256 channels) with ReLU activations, followed by flattening and dense layers to output mu and logvar for the latent space (128 dimensions).
  • Decoder :
  • Input: Latent vector (128 dimensions)
  • Layers: Dense layers to 256x8x8, followed by four transposed convolutional layers (256→128→64→32→1 channels) with ReLU activations and a final Sigmoid activation.
  • Loss : Combination of Mean Squared Error (MSE) for reconstruction and KL-divergence for latent space regularization.

Sensor Encoder

  • Input : Sensor data (2x13x13, real and imaginary parts)
  • Layers : Three convolutional layers (2→32→64→128 channels) with ReLU activations, followed by flattening and dense layers to output mu and logvar (128 dimensions).
  • Loss : Combination of MSE for reconstructed images (via Image VAE decoder), and MSE losses for matching mu and logvar to the Image VAE's latent space.

Video: Training Development

Below is a video that demonstrates the training development of recreated images from sensor data over time. The video should showcase the progression of image quality in sensor_reconstructions/recon_epoch_<N>.png files across epochs.

Processing demo

Fig 1: VAE Training development

Processing demo

Fig 2: Sensor Encoder Training development

Notes

  • Device : The code automatically uses CUDA if available; otherwise, it falls back to CPU.
  • Caching : Sensor data is cached as .pt files to reduce loading time. Set cache=False in ImageSensorDataset to disable caching.
  • Data Assumptions : The dataset is expected to follow the naming conventions specified in preprocess.py. Ensure your data matches these patterns.
  • Hyperparameters :
  • Image VAE: latent_dim=128, lr=1e-4, epochs=50
  • Sensor Encoder: latent_dim=128, lr=1e-3, epochs=50
  • Adjust these in the training functions as needed.
  • Transformations : Customize sensor_data_transform and image_transform in preprocess.py to experiment with different data augmentations.

Future Improvements

  • Experiment with different latent dimensions or network architectures.
  • Add regularization techniques (e.g., dropout) to prevent overfitting.
  • Implement additional loss terms (e.g., perceptual loss) for better image quality.
  • Optimize caching mechanism for larger datasets.

Contact

For questions or contributions, please open an issue or submit a pull request on the project repository.

About

Microwave Imaging ML uses machine learning, autoencoders, and neural networks to reconstruct electromagnetic images from S-parameters and scattered fields, enabling non-invasive monitoring, permittivity estimation, and advanced material characterization.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages