How to do it...

You need to complete the following steps:

  1. Import the modules:
import cv2import numpy as np
  1. 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 net.empty():    print('Net loaded successfully\n')    print('Net contains:')for t in net.getLayerTypes():    print('\t%d layers of type %s' % (net.getLayersCount(t), t))
  1. Get the tensor shapes for the loaded model and specified input shape. Then print all of the information:
layers_ids, in_shapes, out_shapes = net.getLayersShapes([1, 3, 224, 224])layers_names = net.getLayerNames()print('Net layers shapes:')for l in range(len(layers_names)): ...

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.