The Salinas HSI contains 16 classes such as Broccoli Green Weeds, Fallow, Stubble, Celery, Grapes, Vine Yard, Corn, Lettuce, e.t.c. The below figure shows the information about the classes along with the number of samples.
The ground truth of the salinas HSI data is shown below, the spectral samples of the HSI contain no information which is defined as Zero (0) and they have to be discarded before the analysis and they are depicted in black color.
Let’s build a one dimensional CNN with different layers such as Convolution, Maxpooling, Dropout, and Dense Layers.
The architecture of the CNN model is shown below:
Let’s start by loading the data, the salinas data is available in the .mat format. The below coded serves the purpose of loading the data and converting the data into a pandas data frame for further processing.
The below code normalizes the data and splits the data into train and test in the ratio of 70:30.
A brief explanation of optimizer, loss, and callbacks used for training the DNN.
Adam Optimizer
Adam is an optimization algorithm that can be used instead of the classical stochastic gradient descent procedure to update network weights iterative based on training data. The advantages of using adam optimizer are:
- Straightforward to implement.
- Computationally efficient.
- Little memory requirements.
- Invariant to diagonal rescale of the gradients.
- Well suited for problems that are large in terms of data and/or parameters.
- Appropriate for non-stationary objectives.
- Appropriate for problems with very noisy/or sparse gradients.
- Hyper-parameters have intuitive interpretation and typically require little tuning.
Categorical Crossentropy
Cross-entropy is the default loss function to use for multi-class classification problems. In this case, it is intended for use with multi-class classification where the target values are in the set {0, 1, 3, …, n}, where each class is assigned a unique integer value. Mathematically, it is the preferred loss function under the inference framework of maximum likelihood. It is the loss function to be evaluated first and only changed if you have a good reason.
Cross-entropy will calculate a score that summarizes the average difference between the actual and predicted probability distributions for all classes in the problem. The score is minimized and a perfect cross-entropy value is 0.
Cross-entropy can be specified as the loss function in Keras by specifying ‘categorical_crossentropy‘ when compiling the model.
Different callbacks are such as Model Check Point, Early Stopping, and TensorBoard.
Callbacks
EarlyStopping: One technique to reduce overfitting in neural networks is to use early stopping. Early stopping prevents overtraining of your model by terminating the training process if it’s not really learning anything. This is pretty flexible — you can control what metric to monitor, how much it needs to change to be considered “still learning”, and how many epochs in a row it can falter before the model stops training.
ModelCheckpoint: This callback will save your model as a checkpoint file (in hdf5 or h5
format) to disk after each successful epoch. You can actually set the output file to be dynamically named based on the epoch. You can also write either the loss value or accuracy value as part of the log’s file name.
The below code is used to train the CNN model.
Graphs
The code for the Accuracy and Loss graph during the training is shown below and the X-Axis represents epochs and Y-Axis represents the Percentage.