aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorsteniu01 <steven.niu@arm.com>2017-06-21 16:45:41 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-09-17 14:14:20 +0100
commitbee466b5eac4ec39d4032d946c9a4aee051f2b31 (patch)
tree264e5124e7d2e1ccb3277b0ef478f0bb4a145a0a /scripts
parent8af2dd6eb230f2205070dce50c2a22bdf2d55e46 (diff)
downloadComputeLibrary-bee466b5eac4ec39d4032d946c9a4aee051f2b31.tar.gz
COMPID-345 Add caffe_data_extractor.py script and the instructions
Change-Id: Ibb84b2060c4d6362be9ce4b1757e273e013de618 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/78630 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/caffe_data_extractor.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/caffe_data_extractor.py b/scripts/caffe_data_extractor.py
new file mode 100755
index 0000000000..09ea0b86b0
--- /dev/null
+++ b/scripts/caffe_data_extractor.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+import argparse
+
+import caffe
+import numpy as np
+import scipy.io
+
+
+if __name__ == "__main__":
+ # Parse arguments
+ parser = argparse.ArgumentParser('Extract CNN hyper-parameters')
+ parser.add_argument('-m', dest='modelFile', type=str, required=True, help='Caffe model file')
+ parser.add_argument('-n', dest='netFile', type=str, required=True, help='Caffe netlist')
+ args = parser.parse_args()
+
+ # Create Caffe Net
+ net = caffe.Net(args.netFile, 1, weights=args.modelFile)
+
+ # Read and dump blobs
+ for name, blobs in net.params.iteritems():
+ print 'Name: {0}, Blobs: {1}'.format(name, len(blobs))
+ for i in range(len(blobs)):
+ # Weights
+ if i == 0:
+ outname = name + "_w"
+ # Bias
+ elif i == 1:
+ outname = name + "_b"
+ else:
+ pass
+
+ print("%s : %s" % (outname, blobs[i].data.shape))
+ # Dump as binary
+ blobs[i].data.tofile(outname + ".dat")