Loading deep learning models from Caffe, Torch, and TensorFlow formats
One of the great features of OpenCV's dnn
module is being able to load trained models from three very popular frameworks: Caffe
, Torch
, and TensorFlow
. Not only does it makes the dnn
module very useful, but also it opens up the possibility of combining models from different frameworks into a single pipeline. In this recipe, we will learn how to work with networks from these three frameworks.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV 3.3.1 (or higher) Python API package.
How to do it...
Go through the following steps:
- Import the modules:
import cv2 import numpy as np
- Load a
Caffe
model:
net_caffe = cv2.dnn.readNetFromCaffe('../data/bvlc_googlenet.prototxt', '../data/bvlc_googlenet.caffemodel')
- Load a model from
Torch
:
net_torch = cv2.dnn.readNetFromTorch('../data/torch_enet_model.net')
- Read and parse a
TensorFlow
trained model:
net_tensorflow = cv2.dnn.readNetFromTensorflow...