diff --git a/.tools/build_docker.sh b/.tools/build_docker.sh index 681c2bbd7d224247bf6f7345b275f7971138b70b..2029819eedfd7561949944728fdeb1545e839094 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 3ed49f0a0dad05488100abca064aa702664ab041..ac43473538c124acbcdfc586c35b8a488e50d413 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 0eee811ec19e8d3c7486b1abea773bc23cfe55bc..1b41aa4c67a71b71c408b9ec518229dd4d1c5484 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 82bcd531c7db05bf95462653a42ddf8537813be5..e5d0d47435cadaa0f51ab2ceebb848b7ca1086e0 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 b7534329942e3d21d9a1eb2d9b120446a806f6a0..56cde19b6bdb439c1084a36e01405e3cfb6ea692 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) ```