Make predictions with pre-trained deep learning model (GoogleLeNet) in Caffe using OpenCV
All thanks to Adrian Rosebrock (from pyimagesearch) for making great tutorials. This project is inspired from his blog: Deep Learning with OpenCV. I have included the author's code and the one I wrote my self as well.
- Steps involved:
- Load the image from disk
- Load the Caffe model architecture and weights in OpenCV
- Make a forward pass and print the top-5 predictions
- Assumptions:
- We already have the trained Caffe model.
- Our test image lies in the 1000 classes from ImageNet
- The model is trained on ImageNet dataset that has 1000 classes.
- With the release of OpenCV 3.3, the dnn module is not officially part of OpenCV. Before that it came in opencv_contrib from release 3.1.
- dnn module supports a number of deep learning frameworks which includes Caffe, Tensorflow and Torch/PyTorch. Keras is not yet supported.
- We cannot train a deep learning model with OpenCV but we can load pre-trained model and make predictions with it.
- Popular network architectures compatible with OpenCV 3.3 include:
- GoogleLeNet
- AlexNet
- SqueezeNet
- VGGNet
- ResNet
- Aleksandr Rybnikov is the main contributor of dnn module.
- I created the python script that can be used to classify input images using OpenCV and GoogleLeNet (pre-trained on ImageNet) using the Caffe framework.
- We need two files for Caffe network:
- prototxt file: defines the model architecture
- caffemodel file: stores the model weights
- We show the top prediction on the image and prints the top-5 predictions on terminal.
- python (3.7.3)
- opencv (4.1.0)
- numpy (1.61.4)
python deep_learning_with_opencv_mine.py --image images/jemma.png --prototxt bvlc_googlenet.prototxt \
--model bvlc_googlenet.caffemodel --labels synset_words.txt
The results are pretty accurate. The model works well with OpenCV and gave very good prediction results.
None