Measuring inference time and contributions to it from each layer
In this recipe, you will learn how to compute the total number of floating point operations in a network performed in forward pass, as well as the amount of memory consumed. This is useful when you want to understand the limitations of your model and reveal where exactly the bottlenecks are so that you can optimize it.
Getting ready
Before you proceed with this recipe, you need to install OpenCV 3.x with Python API support.
How to do it...
You need to perform the following steps:
- Import the modules:
import cv2 import numpy as np
- Import the
Caffe
model:
model = cv2.dnn.readNetFromCaffe('../data/bvlc_googlenet.prototxt', '../data/bvlc_googlenet.caffemodel')
- Compute the number of FLOPs performed in the inference stage:
print('gflops:', model.getFLOPS((1,3,224,224))*1e-9)
- Report the amount of memory consumed for storing weights and intermediate tensors:
w,b = model.getMemoryConsumption((1,3,224,224)) print...