You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by zh...@apache.org on 2021/03/10 14:01:13 UTC
[singa] branch dev updated: Update the MLP example
This is an automated email from the ASF dual-hosted git repository.
zhaojing pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/singa.git
The following commit(s) were added to refs/heads/dev by this push:
new b637f7d Update the MLP example
new a2606a7 Merge pull request #835 from KimballCai/dev
b637f7d is described below
commit b637f7dcdf2fd905e4af789c0642a4fdc349e66a
Author: KimballCai <qi...@u.nus.edu>
AuthorDate: Wed Mar 10 21:30:14 2021 +0800
Update the MLP example
---
examples/mlp/model.py | 8 ++++++--
examples/mlp/native.py | 6 ++++--
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/examples/mlp/model.py b/examples/mlp/model.py
index 73cd99f..9a6f3a7 100644
--- a/examples/mlp/model.py
+++ b/examples/mlp/model.py
@@ -76,7 +76,10 @@ def create_model(pretrained=False, **kwargs):
"""Constructs a CNN model.
Args:
- pretrained (bool): If True, returns a model pre-trained
+ pretrained (bool): If True, returns a pre-trained model.
+
+ Returns:
+ The created CNN model.
"""
model = MLP(**kwargs)
@@ -111,6 +114,7 @@ if __name__ == "__main__":
f = lambda x: (5 * x + 1)
bd_x = np.linspace(-1.0, 1, 200)
bd_y = f(bd_x)
+
# generate the training data
x = np.random.uniform(-1, 1, 400)
y = f(x) + 2 * np.random.randn(len(x))
@@ -129,7 +133,7 @@ if __name__ == "__main__":
ty = tensor.Tensor((400,), dev, tensor.int32)
model = MLP(data_size=2, perceptron_size=3, num_classes=2)
- # attached model to graph
+ # attach model to graph
model.set_optimizer(sgd)
model.compile([tx], is_train=True, use_graph=args.graph, sequential=True)
model.train()
diff --git a/examples/mlp/native.py b/examples/mlp/native.py
index 03ff7fd..a82ec3b 100644
--- a/examples/mlp/native.py
+++ b/examples/mlp/native.py
@@ -53,9 +53,11 @@ if __name__ == "__main__":
f = lambda x: (5 * x + 1)
bd_x = np.linspace(-1.0, 1, 200)
bd_y = f(bd_x)
+
# generate the training data
x = np.random.uniform(-1, 1, 400)
y = f(x) + 2 * np.random.randn(len(x))
+
# convert training data to 2d space
label = np.asarray([5 * a + 1 > b for (a, b) in zip(x, y)])
data = np.array([[a, b] for (a, b) in zip(x, y)], dtype=np.float32)
@@ -64,12 +66,12 @@ if __name__ == "__main__":
"""
Converts a class vector (integers) to binary class matrix.
- Args
+ Args:
y: class vector to be converted into a matrix
(integers from 0 to num_classes).
num_classes: total number of classes.
- Return
+ Returns:
A binary matrix representation of the input.
"""
y = np.array(y, dtype="int")