[caffe-contrib] 09/09: d: import tests/* from cpu version

Zhou Mo cdluminate-guest at moszumanska.debian.org
Mon Jul 4 13:41:23 UTC 2016


This is an automated email from the git hooks/post-receive script.

cdluminate-guest pushed a commit to branch master
in repository caffe-contrib.

commit 9ef4224cb73097a921ce360dd4a62a429d7b8e9d
Author: Zhou Mo <cdluminate at gmail.com>
Date:   Mon Jul 4 13:40:39 2016 +0000

    d: import tests/* from cpu version
---
 debian/tests/control               |  3 +++
 debian/tests/python-caffe-test.py  | 43 ++++++++++++++++++++++++++++++++++++++
 debian/tests/python3caffetestsuite |  2 ++
 debian/tests/simple                |  9 ++++++++
 4 files changed, 57 insertions(+)

diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..be21b5a
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: simple
+
+Tests: python3caffetestsuite
diff --git a/debian/tests/python-caffe-test.py b/debian/tests/python-caffe-test.py
new file mode 100644
index 0000000..df2c883
--- /dev/null
+++ b/debian/tests/python-caffe-test.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+'''
+Caffe Python Module Testsuite for Debian Package
+Copyright (C) 2016 Zhou Mo
+
+Reference:
+http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/01-learning-lenet.ipynb
+http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/net_surgery.ipynb
+'''
+
+import numpy
+import caffe
+
+def test_lenet_benchmark():
+  # load lenet deploy network
+  model_definition = "examples/mnist/lenet.prototxt"
+  caffe.set_mode_cpu()
+  model = caffe.Net(model_definition, caffe.TEST)
+  # populate random data and copy it to network
+  batch = numpy.random.randn(64, 1, 28, 28)
+  model.blobs['data'].reshape(64, 1, 28, 28)
+  model.blobs['data'].data[...] = batch
+  # randomly fill parameter into network
+  model.params['conv1'][0].data.shape # access test, this should be (20, 1, 5, 5)
+  model.params['conv1'][0].flat = numpy.random.randn(20, 1, 5, 5).flat
+  model.params['conv1'][1].flat = numpy.random.randn(20,).flat
+  model.params['conv2'][0].flat = numpy.random.randn(50, 20, 5, 5).flat
+  model.params['conv2'][1].flat = numpy.random.randn(50,).flat
+  model.params['ip1'][0].flat = numpy.random.randn(500, 800).flat
+  model.params['ip1'][1].flat = numpy.random.randn(500,).flat
+  model.params['ip2'][0].flat = numpy.random.randn(10, 500).flat
+  model.params['ip2'][1].flat = numpy.random.randn(10,).flat
+  # forward this network, here we don't care neither the network parameters nor the result.
+  output = model.forward()
+  output_prob = output['prob'][0] # prob vector for the first image in batch
+  prediction = output_prob.argmax()
+  print ('This mindless benchmark ends up with an arbitary output {}'.format(prediction))
+
+def main():
+  test_lenet_benchmark()
+
+if __name__ == "__main__":
+  main()
diff --git a/debian/tests/python3caffetestsuite b/debian/tests/python3caffetestsuite
new file mode 100755
index 0000000..35a1865
--- /dev/null
+++ b/debian/tests/python3caffetestsuite
@@ -0,0 +1,2 @@
+#!/bin/sh
+python3 python-caffe-test.py
diff --git a/debian/tests/simple b/debian/tests/simple
new file mode 100755
index 0000000..b5824f8
--- /dev/null
+++ b/debian/tests/simple
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -e
+
+# using the deploy version of lenet for a benchmark test, which requires
+# no MNIST dataset.
+model=examples/mnist/lenet.prototxt
+
+# launch a caffe benchmark on the above network
+caffe time -model $model -iterations 50

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/caffe-contrib.git



More information about the debian-science-commits mailing list