How to do it...

You need to perform the following steps:

  1. Import the modules:
import cv2import numpy as np
  1. Import the Caffe model:
model = cv2.dnn.readNetFromCaffe('../data/bvlc_googlenet.prototxt',                                 '../data/bvlc_googlenet.caffemodel')
  1. Compute the number of FLOPs performed in the inference stage:
print('gflops:', model.getFLOPS((1,3,224,224))*1e-9)
  1. Report the amount of memory consumed for storing weights and intermediate tensors:
w,b = model.getMemoryConsumption((1,3,224,224))print('weights (mb):', w*1e-6, ', blobs (mb):', b*1e-6)
  1. Perform a forward pass for a mock input:
blob = cv2.dnn.blobFromImage(np.zeros((224,224,3), np.uint8), 1, (224,224))model.setInput(blob)model.forward()
  1. Report the total time:
total,timings = model.getPerfProfile() ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.