You need to perform the following steps:
- Import the modules:
import cv2import 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('weights (mb):', w*1e-6, ', blobs (mb):', b*1e-6)
- 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()
- Report the total time:
total,timings = model.getPerfProfile() ...