main content

classify images on fpga using quantized neural network -凯发k8网页登录

this example shows how to use deep learning hdl toolbox™ to deploy a quantized deep convolutional neural network (cnn) to an fpga. in the example you use the pretrained resnet-18 cnn to perform transfer learning and quantization. you then deploy the quantized network and use matlab ® to retrieve the prediction results.

resnet-18 has been trained on over a million images and can classify images into 1000 object categories, such as keyboard, coffee mug, pencil, and many animals. the network has learned rich feature representations for a wide range of images. the network takes an image as input and outputs a label for the object in the image together with the probabilities for each of the object categories.

for this example, you need:

  • deep learning toolbox™

  • deep learning hdl toolbox™

  • deep learning toolbox model for resnet-18 network

  • deep learning hdl toolbox™ support package for xilinx® fpga and soc devices

  • image processing toolbox™

  • deep learning toolbox model quantization library

  • matlab® coder™ interface for deep learning

to perform classification on a new set of images, you fine-tune a pretrained resnet-18 cnn by transfer learning. in transfer learning, you can take a pretrained network and use it as a starting point to learn a new task. fine-tuning a network with transfer learning is usually much faster and easier than training a network with randomly initialized weights. you can quickly transfer learned features to a new task using a smaller number of training images.

load pretrained network

load the pretrained resnet-18 network.

net = resnet18;

view the layers of the pretrained network.

deepnetworkdesigner(net);

the first layer, the image input layer, requires input images of size 227-by-227-by-3, where three is the number of color channels.

inputsize = net.layers(1).inputsize;

load data

this example uses the mathworks merchdata data set. this is a small data set containing 75 images of mathworks merchandise, belonging to five different classes (cap, cube, playing cards, screwdriver, and torch).

curdir = pwd;
unzip('merchdata.zip');
imds = imagedatastore('merchdata', ...
'includesubfolders',true, ...
'labelsource','foldernames');

specify training and validation sets

divide the data into training and validation data sets, so that 30% percent of the images go to the training data set and 70% of the images to the validation data set. spliteachlabel splits the datastore imds into two new datastores, imdstrain and imdsvalidation.

[imdstrain,imdsvalidation] = spliteachlabel(imds,0.7,'randomized');

replace final layers

to retrain resnet-18 to classify new images, replace the last fully connected layer and final classification layer of the network. in resnet-18 , these layers have the names 'fc1000' and 'classificationlayer_predictions', respectively. the fully connected layer and classification layer of the pretrained network net are configured for 1000 classes. these two layers fc1000 and classificationlayer_predictions in resnet-18, contain information on how to combine the features that the network extracts into class probabilities and predicted labels. these two layers must be fine-tuned for the new classification problem. extract all the layers, except the last two layers, from the pretrained network.

lgraph = layergraph(net)
lgraph = 
  layergraph with properties:
     inputnames: {'data'}
    outputnames: {'classificationlayer_predictions'}
         layers: [71×1 nnet.cnn.layer.layer]
    connections: [78×2 table]
numclasses = numel(categories(imdstrain.labels))
numclasses = 5
newlearnablelayer = fullyconnectedlayer(numclasses, ...
'name','new_fc', ...
'weightlearnratefactor',10, ...
'biaslearnratefactor',10);
lgraph = replacelayer(lgraph,'fc1000',newlearnablelayer);
newclasslayer = classificationlayer('name','new_classoutput');
lgraph = replacelayer(lgraph,'classificationlayer_predictions',newclasslayer);

prepare data for training

the network requires input images of size 224-by-224-by-3, but the images in the image datastores have different sizes. use an augmented image datastore to automatically resize the training images. specify additional augmentation operations to perform on the training images, such as randomly flipping the training images along the vertical axis and randomly translating them up to 30 pixels horizontally and vertically. data augmentation helps prevent the network from overfitting and memorizing the exact details of the training images.

pixelrange = [-30 30];
imageaugmenter = imagedataaugmenter( ...
'randxreflection',true, ...
'randxtranslation',pixelrange, ...
'randytranslation',pixelrange);

to automatically resize the validation images without performing further data augmentation, use an augmented image datastore without specifying any additional preprocessing operations.

augimdstrain = augmentedimagedatastore(inputsize(1:2),imdstrain, ...
'dataaugmentation',imageaugmenter);
augimdsvalidation = augmentedimagedatastore(inputsize(1:2),imdsvalidation);

specify training options

specify the training options. for transfer learning, keep the features from the early layers of the pretrained network (the transferred layer weights). to slow down learning in the transferred layers, set the initial learning rate to a small value. specify the mini-batch size and validation data. the software validates the network every validationfrequency iterations during training.

options = trainingoptions('sgdm', ...
'minibatchsize',10, ...
'maxepochs',6, ...
'initiallearnrate',1e-4, ...
'shuffle','every-epoch', ...
'validationdata',augimdsvalidation, ...
'validationfrequency',3, ...
'verbose',false, ...
'plots','training-progress');

train network

train the network that consists of the transferred and new layers. by default, trainnetwork uses a gpu if one is available. using this function on a gpu requires parallel computing toolbox™ and a supported gpu device. for more information, see gpu computing requirements (parallel computing toolbox). if a gpu is not available, the network uses a cpu (requires matlab coder interface for deep learning). you can also specify the execution environment by using the executionenvironment name-value argument of trainingoptions.

nettransfer = trainnetwork(augimdstrain,lgraph,options);

quantize network

quantize the network using the dlquantizer object. set the target execution environment to fpga.

dlquantobj = dlquantizer(nettransfer,'executionenvironment','fpga');

calibrate quantized network

use the calibrate function to exercise the network with sample inputs and collect the range information. the calibrate function collects the dynamic ranges of the weights and biases in the convolution and fully connected layers of the network and the dynamic ranges of the activations in all layers of the network. the function returns the information as a table, in which each row contains range information for a learnable parameter of the quantized network.

calibrate(dlquantobj,augimdstrain)
ans=95×5 table
       optimized layer name       network layer name    learnables / activations    minvalue    maxvalue
    __________________________    __________________    ________________________    ________    ________
    {'conv1_weights'         }    {'conv1'         }           "weights"            -0.79143     1.2547 
    {'conv1_bias'            }    {'conv1'         }           "bias"               -0.66949    0.67671 
    {'res2a_branch2a_weights'}    {'res2a_branch2a'}           "weights"            -0.42074    0.34251 
    {'res2a_branch2a_bias'   }    {'res2a_branch2a'}           "bias"                -0.8039     1.2488 
    {'res2a_branch2b_weights'}    {'res2a_branch2b'}           "weights"            -0.78524    0.59222 
    {'res2a_branch2b_bias'   }    {'res2a_branch2b'}           "bias"                -1.3835     1.7661 
    {'res2b_branch2a_weights'}    {'res2b_branch2a'}           "weights"             -0.3174    0.33645 
    {'res2b_branch2a_bias'   }    {'res2b_branch2a'}           "bias"                -1.1203     1.5238 
    {'res2b_branch2b_weights'}    {'res2b_branch2b'}           "weights"             -1.1915    0.93059 
    {'res2b_branch2b_bias'   }    {'res2b_branch2b'}           "bias"               -0.81928     1.2022 
    {'res3a_branch2a_weights'}    {'res3a_branch2a'}           "weights"            -0.19735    0.22659 
    {'res3a_branch2a_bias'   }    {'res3a_branch2a'}           "bias"               -0.53009    0.69532 
    {'res3a_branch2b_weights'}    {'res3a_branch2b'}           "weights"            -0.53557    0.72768 
    {'res3a_branch2b_bias'   }    {'res3a_branch2b'}           "bias"               -0.67756     1.1733 
    {'res3a_branch1_weights' }    {'res3a_branch1' }           "weights"            -0.63395    0.97791 
    {'res3a_branch1_bias'    }    {'res3a_branch1' }           "bias"               -0.95277    0.75618 
      ⋮

define fpga board interface

define the target fpga board programming interface by using the dlhdl.target object. create a programming interface with custom name for your target device and an ethernet interface to connect the target device to the host computer.

htarget = dlhdl.target('xilinx','interface','ethernet');

prepare network for deployment

prepare the network for deployment by creating a dlhdl.workflow object. specify the network and bitstream name. ensure that the bitstream name matches the data type and the fpga board that you are targeting. in this example, the target fpga board is the xilinx® zynq® ultrascale ™ mpsoc zcu102 board and the bitstream uses the int8 data type.

hw = dlhdl.workflow(network=dlquantobj,bitstream='zcu102_int8',target=htarget);

compile network

run the compile method of the dlhdl.workflow object to compile the network and generate the instructions, weights, and biases for deployment.

dn = compile(hw,'inputframenumberlimit',15)
### compiling network for deep learning fpga prototyping ...
### targeting fpga bitstream zcu102_int8.
### optimizing network: fused 'nnet.cnn.layer.batchnormalizationlayer' into 'nnet.cnn.layer.convolution2dlayer'
### the network includes the following layers:
     1   'data'                  image input                  224×224×3 images with 'zscore' normalization                          (sw layer)
     2   'conv1'                 2-d convolution              64 7×7×3 convolutions with stride [2  2] and padding [3  3  3  3]     (hw layer)
     3   'conv1_relu'            relu                         relu                                                                  (hw layer)
     4   'pool1'                 2-d max pooling              3×3 max pooling with stride [2  2] and padding [1  1  1  1]           (hw layer)
     5   'res2a_branch2a'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
     6   'res2a_branch2a_relu'   relu                         relu                                                                  (hw layer)
     7   'res2a_branch2b'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
     8   'res2a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
     9   'res2a_relu'            relu                         relu                                                                  (hw layer)
    10   'res2b_branch2a'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
    11   'res2b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    12   'res2b_branch2b'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
    13   'res2b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    14   'res2b_relu'            relu                         relu                                                                  (hw layer)
    15   'res3a_branch2a'        2-d convolution              128 3×3×64 convolutions with stride [2  2] and padding [1  1  1  1]   (hw layer)
    16   'res3a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    17   'res3a_branch2b'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    18   'res3a_branch1'         2-d convolution              128 1×1×64 convolutions with stride [2  2] and padding [0  0  0  0]   (hw layer)
    19   'res3a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    20   'res3a_relu'            relu                         relu                                                                  (hw layer)
    21   'res3b_branch2a'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    22   'res3b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    23   'res3b_branch2b'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    24   'res3b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    25   'res3b_relu'            relu                         relu                                                                  (hw layer)
    26   'res4a_branch2a'        2-d convolution              256 3×3×128 convolutions with stride [2  2] and padding [1  1  1  1]  (hw layer)
    27   'res4a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    28   'res4a_branch2b'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    29   'res4a_branch1'         2-d convolution              256 1×1×128 convolutions with stride [2  2] and padding [0  0  0  0]  (hw layer)
    30   'res4a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    31   'res4a_relu'            relu                         relu                                                                  (hw layer)
    32   'res4b_branch2a'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    33   'res4b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    34   'res4b_branch2b'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    35   'res4b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    36   'res4b_relu'            relu                         relu                                                                  (hw layer)
    37   'res5a_branch2a'        2-d convolution              512 3×3×256 convolutions with stride [2  2] and padding [1  1  1  1]  (hw layer)
    38   'res5a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    39   'res5a_branch2b'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    40   'res5a_branch1'         2-d convolution              512 1×1×256 convolutions with stride [2  2] and padding [0  0  0  0]  (hw layer)
    41   'res5a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    42   'res5a_relu'            relu                         relu                                                                  (hw layer)
    43   'res5b_branch2a'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    44   'res5b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    45   'res5b_branch2b'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    46   'res5b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    47   'res5b_relu'            relu                         relu                                                                  (hw layer)
    48   'pool5'                 2-d global average pooling   2-d global average pooling                                            (hw layer)
    49   'new_fc'                fully connected              5 fully connected layer                                               (hw layer)
    50   'prob'                  softmax                      softmax                                                               (sw layer)
    51   'new_classoutput'       classification output        crossentropyex with 'mathworks cap' and 4 other classes               (sw layer)
                                                                                                                                  
### notice: the layer 'data' with type 'nnet.cnn.layer.imageinputlayer' is implemented in software.
### notice: the layer 'prob' with type 'nnet.cnn.layer.softmaxlayer' is implemented in software.
### notice: the layer 'new_classoutput' with type 'nnet.cnn.layer.classificationoutputlayer' is implemented in software.
### compiling layer group: conv1>>pool1 ...
### compiling layer group: conv1>>pool1 ... complete.
### compiling layer group: res2a_branch2a>>res2a_branch2b ...
### compiling layer group: res2a_branch2a>>res2a_branch2b ... complete.
### compiling layer group: res2b_branch2a>>res2b_branch2b ...
### compiling layer group: res2b_branch2a>>res2b_branch2b ... complete.
### compiling layer group: res3a_branch1 ...
### compiling layer group: res3a_branch1 ... complete.
### compiling layer group: res3a_branch2a>>res3a_branch2b ...
### compiling layer group: res3a_branch2a>>res3a_branch2b ... complete.
### compiling layer group: res3b_branch2a>>res3b_branch2b ...
### compiling layer group: res3b_branch2a>>res3b_branch2b ... complete.
### compiling layer group: res4a_branch1 ...
### compiling layer group: res4a_branch1 ... complete.
### compiling layer group: res4a_branch2a>>res4a_branch2b ...
### compiling layer group: res4a_branch2a>>res4a_branch2b ... complete.
### compiling layer group: res4b_branch2a>>res4b_branch2b ...
### compiling layer group: res4b_branch2a>>res4b_branch2b ... complete.
### compiling layer group: res5a_branch1 ...
### compiling layer group: res5a_branch1 ... complete.
### compiling layer group: res5a_branch2a>>res5a_branch2b ...
### compiling layer group: res5a_branch2a>>res5a_branch2b ... complete.
### compiling layer group: res5b_branch2a>>res5b_branch2b ...
### compiling layer group: res5b_branch2a>>res5b_branch2b ... complete.
### compiling layer group: pool5 ...
### compiling layer group: pool5 ... complete.
### compiling layer group: new_fc ...
### compiling layer group: new_fc ... complete.
### allocating external memory buffers:
          offset_name          offset_address    allocated_space 
    _______________________    ______________    ________________
    "inputdataoffset"           "0x00000000"     "8.0 mb"        
    "outputresultoffset"        "0x00800000"     "4.0 mb"        
    "schedulerdataoffset"       "0x00c00000"     "4.0 mb"        
    "systembufferoffset"        "0x01000000"     "28.0 mb"       
    "instructiondataoffset"     "0x02c00000"     "4.0 mb"        
    "convweightdataoffset"      "0x03000000"     "16.0 mb"       
    "fcweightdataoffset"        "0x04000000"     "4.0 mb"        
    "endoffset"                 "0x04400000"     "total: 68.0 mb"
### network compilation complete.
dn = struct with fields:
             weights: [1×1 struct]
        instructions: [1×1 struct]
           registers: [1×1 struct]
    syncinstructions: [1×1 struct]
        constantdata: {}
             ddrinfo: [1×1 struct]

program bitstream onto fpga and download network weights

to deploy the network on the xilinx zcu102 hardware, run the deploy function of the dlhdl.workflow object. this function uses the output of the compile function to program the fpga board by using the programming file. it also downloads the network weights and biases. the deploy function starts programming the fpga device, displays progress messages, and the time it takes to deploy the network.

deploy(hw)
### programming fpga bitstream using ethernet...
### attempting to connect to the hardware board at 192.168.1.101...
### connection successful
### programming fpga device on xilinx soc hardware board at 192.168.1.101...
### copying fpga programming files to sd card...
### setting fpga bitstream and devicetree for boot...
# copying bitstream zcu102_int8.bit to /mnt/hdlcoder_rd
# set bitstream to hdlcoder_rd/zcu102_int8.bit
# copying devicetree devicetree_dlhdl.dtb to /mnt/hdlcoder_rd
# set devicetree to hdlcoder_rd/devicetree_dlhdl.dtb
# set up boot for reference design: 'axi-stream ddr memory access : 3-axim'
### rebooting xilinx soc at 192.168.1.101...
### reboot may take several seconds...
### attempting to connect to the hardware board at 192.168.1.101...
### connection successful
### programming the fpga bitstream has been completed successfully.
### loading weights to conv processor.
### conv weights loaded. current time is 21-dec-2022 10:45:19
### loading weights to fc processor.
### fc weights loaded. current time is 21-dec-2022 10:45:19

test network

load the example image.

imgfile = fullfile(pwd,'merchdata','mathworks cube','mathworks cube_0.jpg');
inputimg = imresize(imread(imgfile),[224 224]);
imshow(inputimg)

classify the image on the fpga by using the predict method of the dlhdl.workflow object and display the results.

[prediction,speed] = predict(hw,single(inputimg),'profile','on');
### finished writing input activations.
### running single input activation.
              deep learning processor profiler performance results
                   lastframelatency(cycles)   lastframelatency(seconds)       framesnum      total latency     frames/s
                         -------------             -------------              ---------        ---------       ---------
network                    7392114                  0.02957                       1            7394677             33.8
    conv1                  1115165                  0.00446 
    pool1                   199164                  0.00080 
    res2a_branch2a          270125                  0.00108 
    res2a_branch2b          269946                  0.00108 
    res2a                   102255                  0.00041 
    res2b_branch2a          269792                  0.00108 
    res2b_branch2b          269902                  0.00108 
    res2b                   102695                  0.00041 
    res3a_branch1           155120                  0.00062 
    res3a_branch2a          156480                  0.00063 
    res3a_branch2b          244913                  0.00098 
    res3a                    51456                  0.00021 
    res3b_branch2a          245366                  0.00098 
    res3b_branch2b          245123                  0.00098 
    res3b                    51286                  0.00021 
    res4a_branch1           135535                  0.00054 
    res4a_branch2a          136117                  0.00054 
    res4a_branch2b          238454                  0.00095 
    res4a                    25602                  0.00010 
    res4b_branch2a          237909                  0.00095 
    res4b_branch2b          238282                  0.00095 
    res4b                    26742                  0.00011 
    res5a_branch1           324642                  0.00130 
    res5a_branch2a          325897                  0.00130 
    res5a_branch2b          623521                  0.00249 
    res5a                    13881                  0.00006 
    res5b_branch2a          624028                  0.00250 
    res5b_branch2b          624631                  0.00250 
    res5b                    13051                  0.00005 
    pool5                    37083                  0.00015 
    new_fc                   17764                  0.00007 
 * the clock frequency of the dl processor is: 250mhz
[val,idx] = max(prediction);
dlquantobj.networkobject.layers(end).classnames{idx}
ans = 
'mathworks cube'

performance comparison

compare the performance of the quantized network to the performance of the single data type network.

optionsfpga = dlquantizationoptions('bitstream','zcu102_int8','target',htarget);
predictionfpga = validate(dlquantobj,imdsvalidation,optionsfpga)
### compiling network for deep learning fpga prototyping ...
### targeting fpga bitstream zcu102_int8.
### optimizing network: fused 'nnet.cnn.layer.batchnormalizationlayer' into 'nnet.cnn.layer.convolution2dlayer'
### the network includes the following layers:
     1   'data'                  image input                  224×224×3 images with 'zscore' normalization                          (sw layer)
     2   'conv1'                 2-d convolution              64 7×7×3 convolutions with stride [2  2] and padding [3  3  3  3]     (hw layer)
     3   'conv1_relu'            relu                         relu                                                                  (hw layer)
     4   'pool1'                 2-d max pooling              3×3 max pooling with stride [2  2] and padding [1  1  1  1]           (hw layer)
     5   'res2a_branch2a'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
     6   'res2a_branch2a_relu'   relu                         relu                                                                  (hw layer)
     7   'res2a_branch2b'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
     8   'res2a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
     9   'res2a_relu'            relu                         relu                                                                  (hw layer)
    10   'res2b_branch2a'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
    11   'res2b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    12   'res2b_branch2b'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
    13   'res2b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    14   'res2b_relu'            relu                         relu                                                                  (hw layer)
    15   'res3a_branch2a'        2-d convolution              128 3×3×64 convolutions with stride [2  2] and padding [1  1  1  1]   (hw layer)
    16   'res3a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    17   'res3a_branch2b'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    18   'res3a_branch1'         2-d convolution              128 1×1×64 convolutions with stride [2  2] and padding [0  0  0  0]   (hw layer)
    19   'res3a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    20   'res3a_relu'            relu                         relu                                                                  (hw layer)
    21   'res3b_branch2a'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    22   'res3b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    23   'res3b_branch2b'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    24   'res3b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    25   'res3b_relu'            relu                         relu                                                                  (hw layer)
    26   'res4a_branch2a'        2-d convolution              256 3×3×128 convolutions with stride [2  2] and padding [1  1  1  1]  (hw layer)
    27   'res4a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    28   'res4a_branch2b'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    29   'res4a_branch1'         2-d convolution              256 1×1×128 convolutions with stride [2  2] and padding [0  0  0  0]  (hw layer)
    30   'res4a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    31   'res4a_relu'            relu                         relu                                                                  (hw layer)
    32   'res4b_branch2a'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    33   'res4b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    34   'res4b_branch2b'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    35   'res4b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    36   'res4b_relu'            relu                         relu                                                                  (hw layer)
    37   'res5a_branch2a'        2-d convolution              512 3×3×256 convolutions with stride [2  2] and padding [1  1  1  1]  (hw layer)
    38   'res5a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    39   'res5a_branch2b'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    40   'res5a_branch1'         2-d convolution              512 1×1×256 convolutions with stride [2  2] and padding [0  0  0  0]  (hw layer)
    41   'res5a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    42   'res5a_relu'            relu                         relu                                                                  (hw layer)
    43   'res5b_branch2a'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    44   'res5b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    45   'res5b_branch2b'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    46   'res5b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    47   'res5b_relu'            relu                         relu                                                                  (hw layer)
    48   'pool5'                 2-d global average pooling   2-d global average pooling                                            (hw layer)
    49   'new_fc'                fully connected              5 fully connected layer                                               (hw layer)
    50   'prob'                  softmax                      softmax                                                               (sw layer)
    51   'new_classoutput'       classification output        crossentropyex with 'mathworks cap' and 4 other classes               (sw layer)
                                                                                                                                  
### notice: the layer 'data' with type 'nnet.cnn.layer.imageinputlayer' is implemented in software.
### notice: the layer 'prob' with type 'nnet.cnn.layer.softmaxlayer' is implemented in software.
### notice: the layer 'new_classoutput' with type 'nnet.cnn.layer.classificationoutputlayer' is implemented in software.
### compiling layer group: conv1>>pool1 ...
### compiling layer group: conv1>>pool1 ... complete.
### compiling layer group: res2a_branch2a>>res2a_branch2b ...
### compiling layer group: res2a_branch2a>>res2a_branch2b ... complete.
### compiling layer group: res2b_branch2a>>res2b_branch2b ...
### compiling layer group: res2b_branch2a>>res2b_branch2b ... complete.
### compiling layer group: res3a_branch1 ...
### compiling layer group: res3a_branch1 ... complete.
### compiling layer group: res3a_branch2a>>res3a_branch2b ...
### compiling layer group: res3a_branch2a>>res3a_branch2b ... complete.
### compiling layer group: res3b_branch2a>>res3b_branch2b ...
### compiling layer group: res3b_branch2a>>res3b_branch2b ... complete.
### compiling layer group: res4a_branch1 ...
### compiling layer group: res4a_branch1 ... complete.
### compiling layer group: res4a_branch2a>>res4a_branch2b ...
### compiling layer group: res4a_branch2a>>res4a_branch2b ... complete.
### compiling layer group: res4b_branch2a>>res4b_branch2b ...
### compiling layer group: res4b_branch2a>>res4b_branch2b ... complete.
### compiling layer group: res5a_branch1 ...
### compiling layer group: res5a_branch1 ... complete.
### compiling layer group: res5a_branch2a>>res5a_branch2b ...
### compiling layer group: res5a_branch2a>>res5a_branch2b ... complete.
### compiling layer group: res5b_branch2a>>res5b_branch2b ...
### compiling layer group: res5b_branch2a>>res5b_branch2b ... complete.
### compiling layer group: pool5 ...
### compiling layer group: pool5 ... complete.
### compiling layer group: new_fc ...
### compiling layer group: new_fc ... complete.
### allocating external memory buffers:
          offset_name          offset_address    allocated_space 
    _______________________    ______________    ________________
    "inputdataoffset"           "0x00000000"     "12.0 mb"       
    "outputresultoffset"        "0x00c00000"     "4.0 mb"        
    "schedulerdataoffset"       "0x01000000"     "4.0 mb"        
    "systembufferoffset"        "0x01400000"     "28.0 mb"       
    "instructiondataoffset"     "0x03000000"     "4.0 mb"        
    "convweightdataoffset"      "0x03400000"     "16.0 mb"       
    "fcweightdataoffset"        "0x04400000"     "4.0 mb"        
    "endoffset"                 "0x04800000"     "total: 72.0 mb"
### network compilation complete.
### fpga bitstream programming has been skipped as the same bitstream is already loaded on the target fpga.
### loading weights to conv processor.
### conv weights loaded. current time is 21-dec-2022 10:46:36
### loading weights to fc processor.
### fc weights loaded. current time is 21-dec-2022 10:46:36
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
### finished writing input activations.
### running single input activation.
              deep learning processor bitstream build info
resource                   utilized           total        percentage
------------------        ----------      ------------    ------------
luts (clb/alm)*              249703            274080           91.11
dsps                            391              2520           15.52
block ram                       583               912           63.93
* lut count represents configurable logic block(clb) utilization in xilinx devices and adaptive logic module (alm) utilization in intel devices.
### optimizing network: fused 'nnet.cnn.layer.batchnormalizationlayer' into 'nnet.cnn.layer.convolution2dlayer'
### notice: the layer 'data' of type 'imageinputlayer' is split into an image input layer 'data', an addition layer 'data_norm_add', and a multiplication layer 'data_norm' for hardware normalization.
### the network includes the following layers:
     1   'data'                  image input                  224×224×3 images with 'zscore' normalization                          (sw layer)
     2   'conv1'                 2-d convolution              64 7×7×3 convolutions with stride [2  2] and padding [3  3  3  3]     (hw layer)
     3   'conv1_relu'            relu                         relu                                                                  (hw layer)
     4   'pool1'                 2-d max pooling              3×3 max pooling with stride [2  2] and padding [1  1  1  1]           (hw layer)
     5   'res2a_branch2a'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
     6   'res2a_branch2a_relu'   relu                         relu                                                                  (hw layer)
     7   'res2a_branch2b'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
     8   'res2a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
     9   'res2a_relu'            relu                         relu                                                                  (hw layer)
    10   'res2b_branch2a'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
    11   'res2b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    12   'res2b_branch2b'        2-d convolution              64 3×3×64 convolutions with stride [1  1] and padding [1  1  1  1]    (hw layer)
    13   'res2b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    14   'res2b_relu'            relu                         relu                                                                  (hw layer)
    15   'res3a_branch2a'        2-d convolution              128 3×3×64 convolutions with stride [2  2] and padding [1  1  1  1]   (hw layer)
    16   'res3a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    17   'res3a_branch2b'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    18   'res3a_branch1'         2-d convolution              128 1×1×64 convolutions with stride [2  2] and padding [0  0  0  0]   (hw layer)
    19   'res3a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    20   'res3a_relu'            relu                         relu                                                                  (hw layer)
    21   'res3b_branch2a'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    22   'res3b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    23   'res3b_branch2b'        2-d convolution              128 3×3×128 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    24   'res3b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    25   'res3b_relu'            relu                         relu                                                                  (hw layer)
    26   'res4a_branch2a'        2-d convolution              256 3×3×128 convolutions with stride [2  2] and padding [1  1  1  1]  (hw layer)
    27   'res4a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    28   'res4a_branch2b'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    29   'res4a_branch1'         2-d convolution              256 1×1×128 convolutions with stride [2  2] and padding [0  0  0  0]  (hw layer)
    30   'res4a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    31   'res4a_relu'            relu                         relu                                                                  (hw layer)
    32   'res4b_branch2a'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    33   'res4b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    34   'res4b_branch2b'        2-d convolution              256 3×3×256 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    35   'res4b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    36   'res4b_relu'            relu                         relu                                                                  (hw layer)
    37   'res5a_branch2a'        2-d convolution              512 3×3×256 convolutions with stride [2  2] and padding [1  1  1  1]  (hw layer)
    38   'res5a_branch2a_relu'   relu                         relu                                                                  (hw layer)
    39   'res5a_branch2b'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    40   'res5a_branch1'         2-d convolution              512 1×1×256 convolutions with stride [2  2] and padding [0  0  0  0]  (hw layer)
    41   'res5a'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    42   'res5a_relu'            relu                         relu                                                                  (hw layer)
    43   'res5b_branch2a'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    44   'res5b_branch2a_relu'   relu                         relu                                                                  (hw layer)
    45   'res5b_branch2b'        2-d convolution              512 3×3×512 convolutions with stride [1  1] and padding [1  1  1  1]  (hw layer)
    46   'res5b'                 addition                     element-wise addition of 2 inputs                                     (hw layer)
    47   'res5b_relu'            relu                         relu                                                                  (hw layer)
    48   'pool5'                 2-d global average pooling   2-d global average pooling                                            (hw layer)
    49   'new_fc'                fully connected              5 fully connected layer                                               (hw layer)
    50   'prob'                  softmax                      softmax                                                               (sw layer)
    51   'new_classoutput'       classification output        crossentropyex with 'mathworks cap' and 4 other classes               (sw layer)
                                                                                                                                  
### notice: the layer 'prob' with type 'nnet.cnn.layer.softmaxlayer' is implemented in software.
### notice: the layer 'new_classoutput' with type 'nnet.cnn.layer.classificationoutputlayer' is implemented in software.
              deep learning processor estimator performance results
                   lastframelatency(cycles)   lastframelatency(seconds)       framesnum      total latency     frames/s
                         -------------             -------------              ---------        ---------       ---------
network                   23502752                  0.10683                       1           23502752              9.4
    data_norm_add           210750                  0.00096 
    data_norm               210750                  0.00096 
    conv1                  2164124                  0.00984 
    pool1                   515064                  0.00234 
    res2a_branch2a          966221                  0.00439 
    res2a_branch2b          966221                  0.00439 
    res2a                   210750                  0.00096 
    res2b_branch2a          966221                  0.00439 
    res2b_branch2b          966221                  0.00439 
    res2b                   210750                  0.00096 
    res3a_branch1           540861                  0.00246 
    res3a_branch2a          540749                  0.00246 
    res3a_branch2b          919117                  0.00418 
    res3a                   105404                  0.00048 
    res3b_branch2a          919117                  0.00418 
    res3b_branch2b          919117                  0.00418 
    res3b                   105404                  0.00048 
    res4a_branch1           503405                  0.00229 
    res4a_branch2a          509261                  0.00231 
    res4a_branch2b          905421                  0.00412 
    res4a                    52724                  0.00024 
    res4b_branch2a          905421                  0.00412 
    res4b_branch2b          905421                  0.00412 
    res4b                    52724                  0.00024 
    res5a_branch1          1039437                  0.00472 
    res5a_branch2a         1046605                  0.00476 
    res5a_branch2b         2005197                  0.00911 
    res5a                    26368                  0.00012 
    res5b_branch2a         2005197                  0.00911 
    res5b_branch2b         2005197                  0.00911 
    res5b                    26368                  0.00012 
    pool5                    54594                  0.00025 
    new_fc                   22571                  0.00010 
 * the clock frequency of the dl processor is: 220mhz

              deep learning processor bitstream build info
resource                   utilized           total        percentage
------------------        ----------      ------------    ------------
luts (clb/alm)*              168099            274080           61.33
dsps                            807              2520           32.02
block ram                       453               912           49.67
* lut count represents configurable logic block(clb) utilization in xilinx devices and adaptive logic module (alm) utilization in intel devices.
### finished writing input activations.
### running single input activation.
predictionfpga = struct with fields:
       numsamples: 20
    metricresults: [1×1 struct]
       statistics: [2×7 table]

view the frames per second performance for the quantized network and single-data-type network. the quantized network has a performance of 33.8 frames per second compared to 9.2 frames per second for the single-data-type network. you can use quantization to improve your frames per second performance, however yo could lose accuracy when you quantize your networks.

predictionfpga.statistics.framespersecond
ans = 2×1
    9.3606
   33.7719

see also

| | | | | | | |

related topics

网站地图