From f9d52720b2433080225033fb97c2b1762048cb84 Mon Sep 17 00:00:00 2001 From: tqchen Date: Tue, 22 Sep 2015 14:33:09 -0700 Subject: [PATCH] Update documents --- doc/python/index.md | 8 ++------ doc/python/model.md | 10 +++++++++- doc/python/ndarray.md | 17 +++++++++++++++++ doc/python/symbol.md | 1 - example/README.md | 3 +-- example/cifar10/README.md | 4 ++++ example/cifar10/cifar10.py | 11 +++++++++++ example/python-howto/README.md | 4 ++++ example/python-howto/multiple_outputs.py | 1 - include/mxnet/ndarray.h | 8 ++++---- src/engine/threaded_engine.h | 13 +++++++------ 11 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 example/python-howto/README.md diff --git a/doc/python/index.md b/doc/python/index.md index dcbcfd57e70d..ee281aff0f36 100644 --- a/doc/python/index.md +++ b/doc/python/index.md @@ -5,21 +5,17 @@ To install the package package, checkout [Build and Installation Instruction](.. There are three types of documents you can find about mxnet. * [Tutorials](#tutorials) are self contained materials that introduces a certain usecases of mxnet. -* [Code Examples](#code-examples) contains links to codes. +* [Code Examples](../../example) contains example codes. * [Python API Documents](#python-api-documents) contains documents about specific module, as well as reference of all API functions. Tutorials --------- * [Python Overview Tutorial](tutorial.md) -Code Examples -------------- -* [CIFAR 10 Example](../../example/cifar10) - Python API Documents -------------------- * [High Level Model Training Related API](model.md) * [NDArray API](ndarray.md) * [Symbolic API](symbol.md) * [KVStore API](kvstore.md) -* [Data Loading API](io.md) \ No newline at end of file +* [Data Loading API](io.md) diff --git a/doc/python/model.md b/doc/python/model.md index 686d698dec0e..3522f3439ca5 100644 --- a/doc/python/model.md +++ b/doc/python/model.md @@ -31,8 +31,16 @@ model = mx.model.FeedForward.create( num_round=num_round, learning_rate=0.01) ``` - You can also use scikit-learn style construct and fit function to create a model. +```python +# create a model using sklearn-style two step way +model = mx.model.FeedForward.create( + softmax, + num_round=num_round, + learning_rate=0.01) + +mode.fit(X=data_set) +``` For more information, you can refer to [Model API Reference](#model-api-reference). Save the Model diff --git a/doc/python/ndarray.md b/doc/python/ndarray.md index 5a966dedae68..d5cc48ee64db 100644 --- a/doc/python/ndarray.md +++ b/doc/python/ndarray.md @@ -103,3 +103,20 @@ NDArray API Reference .. automodule:: mxnet.ndarray :members: ``` + +NDArray Random API Reference +---------------------------- + +```eval_rst +.. automodule:: mxnet.random + :members: +``` + + +Context API Reference +--------------------- + +```eval_rst +.. automodule:: mxnet.context + :members: +``` diff --git a/doc/python/symbol.md b/doc/python/symbol.md index 51bf46cfb160..ac1549906c3e 100644 --- a/doc/python/symbol.md +++ b/doc/python/symbol.md @@ -115,4 +115,3 @@ Execution API Reference .. automodule:: mxnet.executor :members: ``` - diff --git a/example/README.md b/example/README.md index 102cf6bee32d..c55cb460eeb8 100644 --- a/example/README.md +++ b/example/README.md @@ -13,5 +13,4 @@ Python Howto [Python Howto](python-howto) is a folder containing short snippet of code introducing a certain feature of mxnet. -***List of Examples*** -* [Configuring Net to get Multiple Ouputs](python-howto/multiple_outputs.py) + diff --git a/example/cifar10/README.md b/example/cifar10/README.md index fdc2d1916e9f..196df6617f52 100644 --- a/example/cifar10/README.md +++ b/example/cifar10/README.md @@ -1,3 +1,7 @@ +CIFAR 10 Example +================ +* [cifar10.py](cifar10.py) provides an example to train a network-in-network style model on CIFAR-10 + Machine: Dual Xeon E5-1650 3.5GHz, 4 GTX 980, Cuda 6.5 diff --git a/example/cifar10/cifar10.py b/example/cifar10/cifar10.py index c9574881ac83..1c3b75ccde70 100644 --- a/example/cifar10/cifar10.py +++ b/example/cifar10/cifar10.py @@ -123,8 +123,19 @@ def SimpleFactory(data, ch_1x1, ch_3x3): logging.basicConfig(level=logging.DEBUG) gpus = [mx.gpu(i) for i in range(num_gpus)] +# Use create functional style to train a model model = mx.model.FeedForward.create( symbol=softmax, ctx=gpus, X=train_dataiter, eval_data=test_dataiter, num_round=num_round, learning_rate=0.05, momentum=0.9, wd=0.00001) + +# Alternatively, you can use sklearn-style two-step API, as follows +""" +model = mx.model.FeedForward( + symbol=softmax, ctx=gpus, + num_round=num_round, + learning_rate=0.05, momentum=0.9, wd=0.00001) + +model.fit(X=train_dataiter, eval_data=test_dataiter) +""" diff --git a/example/python-howto/README.md b/example/python-howto/README.md new file mode 100644 index 000000000000..e2c0ff924245 --- /dev/null +++ b/example/python-howto/README.md @@ -0,0 +1,4 @@ +Python Howto Examples +===================== +* [Configuring Net to get Multiple Ouputs](python-howto/multiple_outputs.py) +* [Configuring Image Record Iterator](python-howto/data_iter.py) diff --git a/example/python-howto/multiple_outputs.py b/example/python-howto/multiple_outputs.py index f2d3c4e0070c..ab6d6d12356c 100644 --- a/example/python-howto/multiple_outputs.py +++ b/example/python-howto/multiple_outputs.py @@ -18,4 +18,3 @@ # executor.forward() # executor.output[0] will be value of fc1 # executor.output[1] will be value of softmax - diff --git a/include/mxnet/ndarray.h b/include/mxnet/ndarray.h index 10427cb87fbf..f9d21441f09e 100644 --- a/include/mxnet/ndarray.h +++ b/include/mxnet/ndarray.h @@ -313,10 +313,10 @@ class NDArray { if (static_data || delay_alloc) { Engine::Get()->DeleteVariable([](RunContext s) {}, shandle.ctx, var); } else { - Storage::Handle h = this->shandle; - Engine::Get()->DeleteVariable([h](RunContext s) { - Storage::Get()->Free(h); - }, shandle.ctx, var); + Storage::Handle h = this->shandle; + Engine::Get()->DeleteVariable([h](RunContext s) { + Storage::Get()->Free(h); + }, shandle.ctx, var); } } }; diff --git a/src/engine/threaded_engine.h b/src/engine/threaded_engine.h index 3b40798cf8d6..ae793fe62f3e 100644 --- a/src/engine/threaded_engine.h +++ b/src/engine/threaded_engine.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "./engine_impl.h" #include "../common/object_pool.h" @@ -256,13 +257,13 @@ class ThreadedEngine : public Engine { ThreadedEngine::OnCompleteStatic, threaded_opr); if (!shutdown_phase_) { try { - threaded_opr->fn(run_ctx, callback); + threaded_opr->fn(run_ctx, callback); } catch(dmlc::Error &e) { - std::string what = e.what(); - if (what.find("driver shutting down") == std::string::npos && - !shutdown_phase_) { - LOG(FATAL) << e.what(); - } + std::string what = e.what(); + if (what.find("driver shutting down") == std::string::npos && + !shutdown_phase_) { + LOG(FATAL) << e.what(); + } } } else { callback();