[caffe] 01/01: d/tests: add python package testsuite

Zhou Mo cdluminate-guest at moszumanska.debian.org
Fri Jun 3 10:44:43 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.

commit d320ce35258ce67d8efa2dec5a225fce757e5cc5
Author: Zhou Mo <cdluminate at gmail.com>
Date:   Fri Jun 3 10:44:25 2016 +0000

    d/tests: add python package testsuite
---
 debian/tests/control                 |  2 ++
 debian/tests/python-caffe-test.py    | 43 ++++++++++++++++++++++++++++++++++++
 debian/tests/python3_caffe_testsuite |  2 ++
 3 files changed, 47 insertions(+)

diff --git a/debian/tests/control b/debian/tests/control
index 938774c..e888e38 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1 +1,3 @@
 Tests: simple
+
+Tests: python3_caffe_testsuite
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/python3_caffe_testsuite b/debian/tests/python3_caffe_testsuite
new file mode 100755
index 0000000..35a1865
--- /dev/null
+++ b/debian/tests/python3_caffe_testsuite
@@ -0,0 +1,2 @@
+#!/bin/sh
+python3 python-caffe-test.py

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



More information about the debian-science-commits mailing list