From 288484b1ecacb3b92cb1ec1ac9b0900cedee465b Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 24 Apr 2017 13:27:20 +0800 Subject: [PATCH] add htmls --- .tools/build_docker.sh | 1 + 01.fit_a_line/README.en.md | 21 +++++++++++++++++++-- 01.fit_a_line/README.md | 21 +++++++++++++++++++-- 01.fit_a_line/index.en.html | 21 +++++++++++++++++++-- 01.fit_a_line/index.html | 21 +++++++++++++++++++-- 5 files changed, 77 insertions(+), 8 deletions(-) diff --git a/.tools/build_docker.sh b/.tools/build_docker.sh index 681c2bb..2029819 100755 --- a/.tools/build_docker.sh +++ b/.tools/build_docker.sh @@ -67,6 +67,7 @@ RUN ${update_mirror_cmd} apt-get -y install gcc && \ apt-get -y clean && \ localedef -f UTF-8 -i en_US en_US.UTF-8 && \ + pip install --upgrade pip && \ pip install -U pillow matplotlib jupyter numpy requests scipy #convert md to ipynb diff --git a/01.fit_a_line/README.en.md b/01.fit_a_line/README.en.md index 3ed49f0..ac43473 100644 --- a/01.fit_a_line/README.en.md +++ b/01.fit_a_line/README.en.md @@ -162,6 +162,23 @@ feeding={'x': 0, 'y': 1} Moreover, an event handler is provided to print the training progress: +```python +lists = [] + +def event_handler(event): + if isinstance(event, paddle.event.EndIteration): + if event.batch_id % 100 == 0: + print "Pass %d, Batch %d, Cost %f, %s" % ( + event.pass_id, event.batch_id, event.cost, event.metrics) + if isinstance(event, paddle.event.EndPass): + result = trainer.test(reader=paddle.batch( + paddle.dataset.mnist.test(), batch_size=128)) + print "Test with Pass %d, Cost %f, %s\n" % ( + event.pass_id, result.cost, result.metrics) + lists.append((event.pass_id, result.cost, + result.metrics['classification_error_evaluator'])) +``` + ```python # event_handler to print training and testing info from paddle.v2.plot import Ploter @@ -172,7 +189,7 @@ plot_cost = Ploter(train_title, test_title) step = 0 -def event_handler(event): +def event_handler_plot(event): global step if isinstance(event, paddle.event.EndIteration): if step % 10 == 0: # every 10 batches, record a train cost @@ -200,7 +217,7 @@ trainer.train( uci_housing.train(), buf_size=500), batch_size=2), feeding=feeding, - event_handler=event_handler, + event_handler=event_handler_plot, num_passes=30) ``` diff --git a/01.fit_a_line/README.md b/01.fit_a_line/README.md index 0eee811..1b41aa4 100644 --- a/01.fit_a_line/README.md +++ b/01.fit_a_line/README.md @@ -157,6 +157,23 @@ feeding={'x': 0, 'y': 1} 此外,我们还可以提供一个 event handler,来打印训练的进度: +```python +lists = [] + +def event_handler(event): + if isinstance(event, paddle.event.EndIteration): + if event.batch_id % 100 == 0: + print "Pass %d, Batch %d, Cost %f, %s" % ( + event.pass_id, event.batch_id, event.cost, event.metrics) + if isinstance(event, paddle.event.EndPass): + result = trainer.test(reader=paddle.batch( + paddle.dataset.mnist.test(), batch_size=128)) + print "Test with Pass %d, Cost %f, %s\n" % ( + event.pass_id, result.cost, result.metrics) + lists.append((event.pass_id, result.cost, + result.metrics['classification_error_evaluator'])) +``` + ```python # event_handler to print training and testing info from paddle.v2.plot import Ploter @@ -167,7 +184,7 @@ cost_ploter = Ploter(train_title, test_title) step = 0 -def event_handler(event): +def event_handler_plot(event): global step if isinstance(event, paddle.event.EndIteration): if step % 10 == 0: # every 10 batches, record a train cost @@ -195,7 +212,7 @@ trainer.train( uci_housing.train(), buf_size=500), batch_size=2), feeding=feeding, - event_handler=event_handler, + event_handler=event_handler_plot, num_passes=30) ``` diff --git a/01.fit_a_line/index.en.html b/01.fit_a_line/index.en.html index 82bcd53..e5d0d47 100644 --- a/01.fit_a_line/index.en.html +++ b/01.fit_a_line/index.en.html @@ -204,6 +204,23 @@ feeding={'x': 0, 'y': 1} Moreover, an event handler is provided to print the training progress: +```python +lists = [] + +def event_handler(event): + if isinstance(event, paddle.event.EndIteration): + if event.batch_id % 100 == 0: + print "Pass %d, Batch %d, Cost %f, %s" % ( + event.pass_id, event.batch_id, event.cost, event.metrics) + if isinstance(event, paddle.event.EndPass): + result = trainer.test(reader=paddle.batch( + paddle.dataset.mnist.test(), batch_size=128)) + print "Test with Pass %d, Cost %f, %s\n" % ( + event.pass_id, result.cost, result.metrics) + lists.append((event.pass_id, result.cost, + result.metrics['classification_error_evaluator'])) +``` + ```python # event_handler to print training and testing info from paddle.v2.plot import Ploter @@ -214,7 +231,7 @@ plot_cost = Ploter(train_title, test_title) step = 0 -def event_handler(event): +def event_handler_plot(event): global step if isinstance(event, paddle.event.EndIteration): if step % 10 == 0: # every 10 batches, record a train cost @@ -242,7 +259,7 @@ trainer.train( uci_housing.train(), buf_size=500), batch_size=2), feeding=feeding, - event_handler=event_handler, + event_handler=event_handler_plot, num_passes=30) ``` diff --git a/01.fit_a_line/index.html b/01.fit_a_line/index.html index b753432..56cde19 100644 --- a/01.fit_a_line/index.html +++ b/01.fit_a_line/index.html @@ -199,6 +199,23 @@ feeding={'x': 0, 'y': 1} 此外,我们还可以提供一个 event handler,来打印训练的进度: +```python +lists = [] + +def event_handler(event): + if isinstance(event, paddle.event.EndIteration): + if event.batch_id % 100 == 0: + print "Pass %d, Batch %d, Cost %f, %s" % ( + event.pass_id, event.batch_id, event.cost, event.metrics) + if isinstance(event, paddle.event.EndPass): + result = trainer.test(reader=paddle.batch( + paddle.dataset.mnist.test(), batch_size=128)) + print "Test with Pass %d, Cost %f, %s\n" % ( + event.pass_id, result.cost, result.metrics) + lists.append((event.pass_id, result.cost, + result.metrics['classification_error_evaluator'])) +``` + ```python # event_handler to print training and testing info from paddle.v2.plot import Ploter @@ -209,7 +226,7 @@ cost_ploter = Ploter(train_title, test_title) step = 0 -def event_handler(event): +def event_handler_plot(event): global step if isinstance(event, paddle.event.EndIteration): if step % 10 == 0: # every 10 batches, record a train cost @@ -237,7 +254,7 @@ trainer.train( uci_housing.train(), buf_size=500), batch_size=2), feeding=feeding, - event_handler=event_handler, + event_handler=event_handler_plot, num_passes=30) ``` -- GitLab