ML + MobileApp = JaDIS
This repo contains an implementation of a tensorflow model which is then compiled into tensorflow lite model and finally used on an android application to identify dog breeds
Here are some examples of the final project:
Some | examples | of the | App |
---|---|---|---|
For training the convolutional neural network I have used the Stanford Dogs Dataset which contains around 20k images of 120 different dog breeds.
Neural network model lupus_omni_die.py
For the final project I have only trained a model using transfer learning method. The reason why transfer learning was necessary in final implementation is because of the sheer diversity and size of the dataset, training a reliable network which would have acceptable accuracy would require quite a complex architecture which would take an extremely long time on the hardware I have at my disposal. The est accuracy I was able to achieve with standard models was near 30% mark and at that time training the network already took about 5 hours, at which point I have made the decision to try transfer learning which at the end was able to achieve 80% accuracy within only 4 hours of training*.
[*] as you can see on the training chart I could have easily acheived similar acc. within 5 epoch (about 1-hour of training), but I kept it going to see whether my model would achieve better acc. on validation data which wasn't the case.
I have decided to use Densenet201[1][2] pretrained model on imagenet dataset as part of the final model which is used in the android APP. After densenet comes a densely connected layer of 4096 neurons with 50% dropout, at the end there is 120 softmax layer corresponding to every breed of the dataset
As we can see by the examples above the transfer learning model was able to achieve about 80% accuracy after only 5 epochs and after them accuracy on the validation dataset did not increase substantially.
Lastly the model is compiled using TFLite compiler into a .tflite file which then is easily accessed by android app. The trained model loses some accuracy due to compression but is still nonetheless accurate as seen in all the previews
Android App Implementation JustADogIdentificationApp
The final part of the project is the android implementation which actively uses the trained and compiled model to classify a breed of dog currently in front of the device's camera. The app consists of one activity which implements CameraX for live image data which is displayed on preview and fed into the TFLite model which den return predictions which are displayed just below the preview window as a recycler view list. The app only diplays 10 most probable guesses. As of writing this project there was no internal method for easy conversion of image from Yuv to RGB hence I have used a method found on another repo as writing the app wasn't the main point of this project, only implementing a tensorflow trained model into an android app was.
The following project demonstrated power of using pretrained NN for training a new model on dataset that is diversified and contains many classes. Transfer learning allowed to drastically shorten training time and allowed to achieve acceptable accuracy on validation data without huge computational power requirements. The project also works as a proof-of-concept of integrating machine learning models trained with tensorflow library into android application.