Data for training the binary classifier is stored in:
./data/train
There are two numpy files named class_a.npy
and class_b.npy
.
These numpy arrays store image data to train the classifier.
As data is in the numpy array we need a simple script to visualize it. To see images in each numpy array run the script
./src/Visualize.py
Sample images from each array are shown below:
Class A | Class B | Test Image |
---|---|---|
This code is implemented in Keras using Tensorflow API r1.0 backend. You can follow the online instructions to install Tensorflow 1.0. Other dependencies like numpy, scikit-image and matplotlib can be installed by pip.
Model can be trained right off the bat using ./src/Train.py
. Labels are manually encoded using a small script. After training the model is saved in the ./model
directory and the variable is deleted.
Special evaluation metrics are used while training the model for better optimization. They are explained as follows:
-
Matthews Correlation: Matthews_correlation is often regarded as the best measure for binary classification as latest versions of keras removed this useful metrics, I have written a version following source code of previous versions of keras A value close to 1 is often regarded as best.
-
F1 Score: F1 score is often a good measure to gauge a model performance The function below calculates precision and recall and then calculates F1 score using the formula mentioned in the return method
Model is compiled on Catergorical Crossentropy and Adam optimizer.
Saved model can be used for prediction purpose. To predict labels for all images in field.npy
run the script:
./src/To_predict.py
Predicted labels are saved in Labels_predicted_by_trained_model.csv
Results are shown below: