This is the end-to-end implementation of detecting microplastics in water using Hyperspectral Imaging and Generative Adverserial Networks (GANs).
$ git clone https://github.com/akshathmangudi/rgb-to-hyper.git
$ python -m venv <env_name>
$ pip install -r requirements.txt
The repository consists of tow stages:
- One for reconstructing HSI out of RGB images.
- One for running detection on microplastic data.
Step 1: cURL or download the NTIRE2020 dataset.
You can either download it manually or use a downloader like cURL to get
Summary of the Training and Prediction Flow
A. Training Flow (mode = "global"):
-
Model and Optimizer Initialization:
- Instantiate Generator and Discriminator.
- Initialize their respective Adam optimizers.
-
Logging Setup:
- Create a summary_writer for TensorBoard to log training metrics.
-
Checkpoint Path Determination:
- Set checkpoint_path to 'global_ckpt' for global training.
-
Training Execution:
- Call train_gan with all necessary parameters.
- Inside train_gan:
- Checkpoint Restoration: Load existing checkpoints if available.
- Data Loading and Preparation: Load and preprocess paired RGB and HSI images.
- Epoch Loop: For each epoch, shuffle data and iterate over batches.
- Batch Processing: Perform augmentation, train discriminator, train generator, compute metrics, and log progress.
- Checkpoint Saving: Save model states at the end of each epoch.
- Post-Training: Save final metrics and optionally generate sample outputs.
B. Prediction Flow (mode = "predict")
- Checkpoint Restoration:
- Use load_model_and_predict to load the Generator model from the 'global_ckpt' directory.
-
Data Loading:
- Load RGB images designated for prediction.
-
HSI Generation:
- Use the restored Generator to create HSI images from the RGB inputs.
- Output Saving:
- Save the generated HSI images as TIFF files in the specified directory.