You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/08/31 14:32:46 UTC

incubator-singa git commit: fix minor erros from installation.md and examples/cifar10/predict.py

Repository: incubator-singa
Updated Branches:
  refs/heads/master 1996e8a95 -> 0416a0fdf


fix minor erros from installation.md and examples/cifar10/predict.py


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/0416a0fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/0416a0fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/0416a0fd

Branch: refs/heads/master
Commit: 0416a0fdfa63cb1b4f54e438ff5b33d7eb4d8df0
Parents: 1996e8a
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Wed Aug 31 22:25:54 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Wed Aug 31 22:25:54 2016 +0800

----------------------------------------------------------------------
 doc/en/docs/installation.md | 22 +++++++---------------
 examples/char-rnn/sample.py |  2 +-
 examples/cifar10/README.md  |  8 ++++++--
 examples/cifar10/predict.py | 23 ++++++++++++-----------
 4 files changed, 26 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/0416a0fd/doc/en/docs/installation.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/installation.md b/doc/en/docs/installation.md
index a8b0530..6dda3f4 100755
--- a/doc/en/docs/installation.md
+++ b/doc/en/docs/installation.md
@@ -138,27 +138,15 @@ To build cnmem into the wheel file, please change CMakeLists.txt by replacing
 
 ## Build SINGA from source
 
-### From the downloaded `tar.gz` file:
-
-Extract the downloaded. If using CUDA, CNMeM needs to be fetched:
-
-    $ cd $SINGA_ROOT/lib/cnmem/
-    $ git clone https://github.com/NVIDIA/cnmem
-
-### From Git:
-
-Please clone the newest code from [Github](https://github.com/apache/incubator-singa) and execute the following commands,
+The source files could be downloaded either as a [tar.gz file](https://dist.apache.org/repos/dist/dev/incubator/singa/1.0.0/apache-singa-incubating-1.0.0-RC2.tar.gz), or as a git repo
 
     $ git clone https://github.com/apache/incubator-singa.git
     $ cd incubator-singa/
 
-If you use CUDA, then [CNMeM](https://github.com/NVIDIA/cnmem) is necessary,
-which could be downloaded as
-
+    # If you use CUDA, then CNMeM is necessary
     $ git submodule init
     $ git submodule update
 
-
 ### Linux & MacOS
 
 GCC (>=4.8.1) is required to compile SINGA on Linux.
@@ -178,7 +166,11 @@ folder, you need to let cmake know the paths to CUDNN,
     $ export CMAKE_LIBRARY_PATH=<path to cudnn>/lib64:$CMAKE_LIBRARY_PATH
 
 You can use `ccmake ..` to configure the compilation options including using
-generating python binding and changing the installation folder.
+generating python binding and changing the installation folder. Alternatively,
+the options could be switched on by
+
+    $ cmake -DUSE_CUDA=ON -DUSE_PYTHON=ON ..
+
 If the dependent libraries are not in the system default paths, you need to export
 the following environment variables
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/0416a0fd/examples/char-rnn/sample.py
----------------------------------------------------------------------
diff --git a/examples/char-rnn/sample.py b/examples/char-rnn/sample.py
index bbfb28f..9b6e757 100644
--- a/examples/char-rnn/sample.py
+++ b/examples/char-rnn/sample.py
@@ -93,7 +93,7 @@ def sample(model_path, nsamples=100, seed_text='', do_sample=True):
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='sample chars from char-rnn')
-    parser.add_argument('model', type=int, help='the model checkpoint file')
+    parser.add_argument('model', help='the model checkpoint file')
     parser.add_argument('n', type=int, help='num of characters to sample')
     parser.add_argument('--seed', help='seed text string which warms up the '
                         ' rnn states for sampling', default='')

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/0416a0fd/examples/cifar10/README.md
----------------------------------------------------------------------
diff --git a/examples/cifar10/README.md b/examples/cifar10/README.md
index de122f7..0cf069f 100644
--- a/examples/cifar10/README.md
+++ b/examples/cifar10/README.md
@@ -66,5 +66,9 @@ predict.py includes the prediction function
 
 The net is created by loading the previously trained model; Images consist of
 a numpy array of images (one row per image); dev is the training device, e.g.,
-a CudaGPU device or the host CppCPU device; topk labels of each image would be
-returned.
+a CudaGPU device or the host CppCPU device; It returns the topk labels for each instance.
+
+The predict.py file's main function provides an example of using the pre-trained alexnet model to do prediction for new images.
+The 'model.bin' file generated by the training program should be placed at the cifar10 folder to run
+
+        python predict.py

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/0416a0fd/examples/cifar10/predict.py
----------------------------------------------------------------------
diff --git a/examples/cifar10/predict.py b/examples/cifar10/predict.py
index 307a610..f2150f4 100644
--- a/examples/cifar10/predict.py
+++ b/examples/cifar10/predict.py
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # =============================================================================
+'''Predicting the labels for new images using the pre-trained alexnet model'''
 import cPickle as pickle
 import numpy as np
 
@@ -21,7 +22,7 @@ import numpy as np
 
 from singa import device
 from singa import tensor
-import net as ffnet
+import alexnet
 
 
 def predict(net, images, dev, topk=5):
@@ -38,10 +39,10 @@ def predict(net, images, dev, topk=5):
     x.to_device(dev)
     y = net.predict(x)
     y.to_host()
-    y = tensor.to_numpy(y)
-    prob = np.average(y, 0)
+    prob = tensor.to_numpy(y)
+    # prob = np.average(prob, 0)
     labels = np.flipud(np.argsort(prob))  # sort prob in descending order
-    return labels[0:topk], prob[labels[0:topk]]
+    return labels[:, 0:topk]
 
 
 def load_dataset(filepath):
@@ -75,16 +76,16 @@ def load_test_data(dir_path):
 
 
 def compute_image_mean(train_dir):
-    images = np.load(train_dir)
+    images, _ = load_train_data(train_dir)
     return np.average(images, 0)
 
 if __name__ == '__main__':
-    model = ffnet.create_alexnet()
-    model.load('model.bin')
-    cuda = device.create_cuda_gpu()
-    model.to_device(cuda)
+    model = alexnet.create_net(True)
+    model.load('model.bin')  # the checkpoint from train.py
+    dev = device.get_default_device()
+    model.to_device(dev)
 
     mean = compute_image_mean('cifar-10-batches-py')
     test_images, _ = load_test_data('cifar-10-batches-py')
-    # minus mean is for alexnet; vgg uses a different pre-processing strategy
-    print predict(model, test_images - mean, cuda)
+    # predict for two images
+    print predict(model, test_images[0:2] - mean, dev)