An open API service indexing awesome lists of open source software.

https://github.com/demetersson83/spectranet

Classifying 2D spectra using convolutional neural networks.
https://github.com/demetersson83/spectranet

Last synced: 7 months ago
JSON representation

Classifying 2D spectra using convolutional neural networks.

Awesome Lists containing this project

README

          

# SpectraNet

(C) 2022 Mark M. Bailey, PhD

## About
This project is an ongoing effort to develop a method to classify 2D spectal data using convolutional neural networks. The hypothesis is that 2D spectral data, when represented as an array, have the same data structure as an image of bit depth 1, and thus can be classified analogously. While I'm testing this script against images to ensure the proper functioning of the CNN, I ultimately see this being used to classify vibrational spectra that dampen over time, or similar data.

Much of this code was adapted from Gad, Aflak, and Huang, **et al.** (see references below).

Be advised that this is a beta version and its functionality is currently being tested.

## References
* Gad, A. (2018). Building Convolutional Neural Network using NumPy from Scratch. **Towards Data Science.** https://towardsdatascience.com/building-convolutional-neural-network-using-numpy-from-scratch-b30aac50e50a
* Aflak, O. (2018). Neural Network from Scratch in Python. **Towards Data Science.** https://towardsdatascience.com/math-neural-network-from-scratch-in-python-d6da9f29ce65
* Huang, G., Mattar, M., Lee, H., & Learned-Miller, E. G. (2012). Learning to align from scratch. In Advances in Neural Information Processing Systems (pp. 764-772). https://scikit-image.org/docs/stable/api/skimage.data.html#skimage.data.lfw_subset

## Updates
* 2022-09-26: Initial commit.

## Contents
* `helper_monkey.py` - Base helper functions and classes.
* `spectrum.py` - Contains ModelBuilder class.

## ModelBuilder Class
`ModelBuilder`

 `load_data(dataset, **options)`


 Loads dataset for training, which should be a 3D array (# of spectra, y-axis, x-axis), or if images (# of images, height, width). Images should be in grayscale. Labels can be input as a list of text labels (which will be converted to integer categorical labels).



 Parameters (required):

  'dataset : `ndarray`' - Stacked spectra or images as Numpy arrays.



 Parameters (optional):

  'dims : `tuple`' - Dimensions for reshaped arrays (rows, columns). Default value is (227, 227).

  'labels : `list`' - list of output labels. Default will result in 10 model output parameters.



 `load_images(filepath, **options)`


 Loads and processes a set of image files from a specified file path. Replaces the reshaped_data attribute. Note all files in directory must be images as this method does not currently sort out non-image files.



 Parameters (required):

  'filepath : `str`' - Path to folder where image files are stored.



 Parameters (optional):

  'dims : `tuple`' - Dimensions for reshaped arrays (rows, columns). Default value is (227, 227).

  'labels : `list`' - list of output labels. Default will result in 10 model output parameters.



 `train(**options)`



 Trains the model on the loaded dataset.



 Parameters (optional):

  'train : `float`' - Training fraction. Default is 0.4.

  'test : `float`' - Testing fraction. Default is 0.6.

  'epochs : `int`' - Total training epochs. Default is 35.

  'learning_rate : `int`' - Learning rate. Default is 0.1.



 `save_model(**options)`



 Saves a copy of the model to the specified (optional) path.



 Parameters (optional):

  'path : `str`' - Absolute path to saved file. Default is 'net.model' in the current directory.



 `load_model(path)`



 Loads model from specified path.



 Parameters (required):

  'path : `str`' - location of model file.