Layer Information

Layer Information

Benanza affords you a few ways to examine the topological structure (or architecture) of models. This section describes the base case, where given a model it prints out all the layers. Subsequent sections describe how to get the layer shape information and layer statistics across models from the tool.

Theoretical Flops

Users can get the theoretical flops of a model by using the flopsinfo command. The command allows one to compute the theoretical flops for each layer within the network.

benanza flopsinfo -h
Get flops information about the model

Usage:
  benanza flopsinfo [flags]

Aliases:
  flopsinfo, flops

Flags:
  -h, --help   help for flopsinfo

Global Flags:
  -b, --batch_size int       batch size (default 1)
  -f, --format string        print format to use (default "automatic")
      --full                 print all information about the layers
      --human                print flops in human form
  -d, --model_dir string     model directory
  -p, --model_path string    path to the model prototxt file
      --no_header            show header labels for output
  -o, --output_file string   output file name

Usage

You can also get the flop information as a table (default). For example, for AlexNet, the theoretical flops are:

benanza flopsinfo --model_path //AlexNet/model.onnx
FLOP TYPE#
MultipleAdds655622016
Additions463184
Divisions906984
Exponentiations453992
Comparisons1623808
General0
Total1314692000

You can also get the theoretical flops of each layer AlexNet. This is done by passing the --full option and here we pass the --human option to make the output more readable.

benanza flopsinfo --model_path //AlexNet/model.onnx --full --human
LAYERNAMELAYERTYPEMULTIPLYADDSADDITIONSDIVISIONSEXPONENTIATIONSCOMPARISONSGENERALTOTAL
conv_1Conv102 MFlop0 Flops0 Flops0 Flops0 Flops0 Flops203 MFlop
relu_1Relu280 kFlop0 Flops0 Flops0 Flops280 kFlop0 Flops840 kFlop
lrn_1LRN280 kFlop280 kFlop560 kFlop280 kFlop0 Flops0 Flops1.7 MFlop
maxpool_1Pooling0 Flops0 Flops0 Flops0 Flops584 kFlop0 Flops584 kFlop
conv2_2Conv208 MFlop0 Flops0 Flops0 Flops0 Flops0 Flops415 MFlop
relu_2Relu173 kFlop0 Flops0 Flops0 Flops173 kFlop0 Flops519 kFlop
lrn_2LRN173 kFlop173 kFlop346 kFlop173 kFlop0 Flops0 Flops1.0 MFlop
maxpool_2Pooling0 Flops0 Flops0 Flops0 Flops332 kFlop0 Flops332 kFlop
conv_3Conv127 MFlop0 Flops0 Flops0 Flops0 Flops0 Flops255 MFlop
relu_3Relu55 kFlop0 Flops0 Flops0 Flops55 kFlop0 Flops166 kFlop
conv4_2Conv96 MFlop0 Flops0 Flops0 Flops0 Flops0 Flops191 MFlop
relu_4Relu55 kFlop0 Flops0 Flops0 Flops55 kFlop0 Flops166 kFlop
conv5_2Conv64 MFlop0 Flops0 Flops0 Flops0 Flops0 Flops127 MFlop
relu_5Relu37 kFlop0 Flops0 Flops0 Flops37 kFlop0 Flops111 kFlop
maxpool_3Pooling0 Flops0 Flops0 Flops0 Flops83 kFlop0 Flops83 kFlop
reshape_1Reshape0 Flops0 Flops0 Flops0 Flops0 Flops0 Flops0 Flops
gemm_1Gemm38 MFlop4.1 kFlop0 Flops0 Flops0 Flops0 Flops76 MFlop
relu_6Relu4.1 kFlop0 Flops0 Flops0 Flops4.1 kFlop0 Flops12 kFlop
dropout_1Dropout0 Flops0 Flops0 Flops0 Flops4.1 kFlop0 Flops4.1 kFlop
dropout_1Dropout0 Flops0 Flops0 Flops0 Flops4.1 kFlop0 Flops4.1 kFlop
gemm_2Gemm17 MFlop4.1 kFlop0 Flops0 Flops0 Flops0 Flops34 MFlop
relu_7Relu4.1 kFlop0 Flops0 Flops0 Flops4.1 kFlop0 Flops12 kFlop
dropout_2Dropout0 Flops0 Flops0 Flops0 Flops4.1 kFlop0 Flops4.1 kFlop
dropout_2Dropout0 Flops0 Flops0 Flops0 Flops4.1 kFlop0 Flops4.1 kFlop
gemm_3Gemm4.1 MFlop1.0 kFlop0 Flops0 Flops0 Flops0 Flops8.2 MFlop
softmax_1Softmax0 Flops1.0 kFlop1.0 kFlop1.0 kFlop0 Flops0 Flops3.0 kFlop

Weight Information

Benanza can examine the weights within the model to compute statistics such as distribution and histogram information. While this is outside the scope of the the paper, it shows that the tool is capable of being extended and generalized to other domains. Here we show how to get weights information for AlexNet

benanza weightsinfo --model_path ///BVLC_AlexNet/model.onnx

The command outputs a table (shown bellow)

LAYERNAMELAYERTYPELENGTHLAYERWEIGHTSMAXLAYERWEIGHTSMINLAYERWEIGHTSSDEV
conv_1Conv349440.44255533814430237-0.8009203076362610.06429448279744572
conv2_2Conv3074560.4831761121749878-0.25868618488311770.02538710473291357
conv_3Conv8851200.46737396717071533-0.218888714909553530.01679956665487417
conv4_2Conv6639360.4463724195957184-0.158476620912551880.018438743467314958
conv5_2Conv4426241.3109842538833618-0.483353495597839360.021065162399881654
gemm_1Gemm377528320.24130532145500183-0.038430374115705490.004962945202842958
gemm_2Gemm167813120.6115601062774658-0.032973639667034150.00794123731339782
gemm_3Gemm40970000.40080997347831726-0.430729836225509640.010868346074723081

The command also generates figures that show the distribution of weights within the layers