Getting input and output tensors' shapes for all layers
Sometimes it's necessary to get information about what's going on with the data shape during a forward pass in deep neural networks. For example, some models allow the usage of various input spatial size and, in that case, you may want to know the output tensors' shapes. OpenCV has an option to get all shapes for all tensors (including intermediate tensors) without inference. This recipe reviews ways of using such functionality along with other useful routines relevant to neural nets.
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...
You need to complete the following steps:
- Import the modules:
import cv2 import numpy as np
- Load a model from
Caffe
and print the information about the types of layers used in the model:
net = cv2.dnn.readNetFromCaffe('../data/bvlc_googlenet.prototxt', '../data/bvlc_googlenet.caffemodel') if not...