Main Content

activations

Class: dlhdl.Workflow
Package: dlhdl

Retrieve intermediate layer results for deployed deep learning network

Description

example

activations(imIn,layername) returns intermediate layer activation data results for the image data in imIn, and the name of the layer specified in layername. The result size depends on the output size of the layer. The layer output size can be retrieved by using analyzeNetwork.

activations(imIn,layername, Name,Value)returns intermediate layer activation data results for the image data in imIn, and the name of the layer specified in layername, with additional options specified by one or more Name,Value pair arguments. The result size depends on the output size of the layer. The layer output size can be retrieved by using analyzeNetwork.

Examples

Retrieve Layer Activation Results

Retrieve the activation results of the LogoNet maxpool_3 layer for a given input image.

Create a file in your current working directory called getLogoNetwork.m. Enter these lines into the file:

function net = getLogoNetwork()
    data = getLogoData();
    net  = data.convnet;
end

function data = getLogoData()
    if ~isfile('LogoNet.mat')
        url = 'https://www.mathworks.com/supportfiles/gpucoder/cnn_models/logo_detection/LogoNet.mat';
        websave('LogoNet.mat',url);
    end
    data = load('LogoNet.mat');
end
snet = getLogoNetwork();
hT = dlhdl.Target('Xilinx');
hW = dlhdl.Workflow('Network','snet','Bitstream','zcu102_single','target',hT);
image = imread('heineken.png');
inputImg = imresize(image, [227, 227]);
imIn = single(inputImg);
results = hW.activations(imIn,'maxpool_3','Profiler','on');

The result of the code execution is a 25-by-25-by-384 matrix for results and

              Deep Learning Processor Profiler Performance Results

                   LastLayerLatency(cycles)   LastLayerLatency(seconds)       FramesNum      Total Latency     Frames/s
                         -------------             -------------              ---------        ---------       ---------
Network                   32497812                  0.14772                       1           32497822              6.8
    conv_module           32497812                  0.14772 
        conv_1             6953894                  0.03161 
        maxpool_1          3305128                  0.01502 
        conv_2            10397281                  0.04726 
        maxpool_2          1207938                  0.00549 
        conv_3             9267269                  0.04212 
        maxpool_3          1366383                  0.00621 
 * The clock frequency of the DL processor is: 220MHz

Input Arguments

expand all

Input image resized to match the input image layer image size of the deep learning network.

Example: To read an input image, resize it to 227x227, and convert it to single use:

Use this image to run the code:

image = imread('heineken.png');
inputImg = imresize(image, [227, 227]);
imIn = single(inputImg);

Example: imIn

Name of the layer in the deployed deep learning network whose results are retrieved for the image specified in imIn.

The layer has to be of the type Convolution, Fully Connected, Max Pooling, ReLU, or Dropout. Convolution and Fully Connected layers are allowed as long as they are not followed by a ReLU layer.

Example: 'maxpool_3'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Flag to return profiling results for the deep learning network deployed to the target board.

Example: 'Profiler','on'

Introduced in R2020b