UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor iljaiv
Visitor
166 Views
Registered: ‎07-18-2018

Memory allocation for models with multiple FC layers

Hello,

How to properly setup inference for models that have several FC layers(e.g. VGG)?

The variable config['outsz'] that represents the number of output elements of FC layers is used for all FC layers, however usually last FC layer has number of outputs equal to number of classes thus it is much smaller than the previous FC layers. For VGG it is 4096 (FC6)-> 4096 (FC7)-> 1000 (FC8).

For VGG-16 I used config['fpgaoutsz'] = 512*7*7 as it is last polling layer executed on the FPGA (setting value less than 512*7*7 results in a notebook crash). 

If for config['outsz'] I use 4096 (first FC layer) then an error in step "Output the classification prediction scores" is given as there are 1000 labels in labels.txt, but 4096 are expected. 

Error:

IndexErrorTraceback (most recent call last)
<ipython-input-13-ae800236b0a6> in <module>()
      2 
      3 config["labels"] = "../examples/classification/synset_words.txt"
----> 4 pyxfdnn_io.printClassification(softmaxOut, config);
      5 
      6 #Print Original Image for Reference

/usr/src/ml-suite/xfdnn/rt/xdnn_io.py in printClassification(output, args)
    237 
    238     for j in range(len(top5)):
--> 239       print "%.4f - \"%s\"" % (top5[j][0], labels[top5[j][1]])
    240     print ""
    241 

IndexError: list index out of range

If for config['outsz'] I use 1000 (last FC layer) then an error in step "Execute the Fully Connected Layers on the CPU" is given as there is weight mismatch.

Code:

config["outsz"] = 1000 # Number of elements output by FC layers
config["useblas"] = True # Accelerate Fully Connected Layers in the CPU

print(len(fcWeight))
print(config['outsz'])
print(config['fpgaoutsz'])

if len(pyxfdnn._xdnnManager._handles) > 0: # Just make sure FPGA still available
fcOut = pyxfdnn.computeFC(
fcWeight,
fcBias,
fpgaOutputs,
batch_sz,
config['outsz'],
config['fpgaoutsz'],
config['useblas'] # Can use cblas if True or numpy if False
)

Error:  

102760448
1000
25088
Exception
Traceback (most recent call last) <ipython-input-10-cae84bad3fbd> in <module>() 14 config['outsz'], 15 config['fpgaoutsz'], ---> 16 config['useblas'] # Can use cblas if True or numpy if False 17 ) /usr/src/ml-suite/xfdnn/rt/xdnn.pyc in computeFC(weight, bias, data, M, N, K, useBlas) 553 K = int(K) 554 if len(weight) != K*N: --> 555 raise Exception('FC weight dim mismatch') 556 if len(data) != M*K: 557 raise Exception('FC input dim mismatch') Exception: FC weight dim mismatch
 
0 Kudos