Main Content

activations

Class: dlhdl.Workflow
Package: dlhdl

Retrieve intermediate layer results for deployed deep learning network

Description

example

activations(image,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(image,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.

Input Arguments

expand all

Input image, specified as a m-by-n-by-3 numeric array. m and n must match the dimensions of the deep learning network input image layer. For example, for the LogoNet network, resize the input images to a 227-by-227-by-3 array.

Data Types: single

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'

Examples

expand all

  1. Create a file in your current working folder 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
  2. Create a dlhdl.Workflow object that has LogoNet as the network argument, zcu102_single as the bitstream argument, and hT as the target argument.

    snet = getLogoNetwork;
    hT = dlhdl.Target('Xilinx');
    hW = dlhdl.Workflow('Network',snet,'Bitstream','zcu102_single','target',hT);
  3. Retrieve a randomized image from the logos_dataset dataset.

    curDir = pwd;
    newDir = fullfile(matlabroot,'examples','deeplearning_shared','data','logos_dataset.zip');
    copyfile(newDir,curDir);
    unzip('logos_dataset.zip');
    imds = imageDatastore('logos_dataset', ...
        'IncludeSubfolders',true, ...
        'LabelSource','foldernames');
    [imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
    index = randperm(numel(imdsValidation.Files),1)
    imIn = readimage(imdsValidation,index)
    inputImg = imresize(imIn, [227 227]);
    

  4. Retrieve the layer results for the maxpool_3 layer by using the activations function.

    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.

                  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

Introduced in R2020b