diff --git a/02.recognize_digits/README.en.md b/02.recognize_digits/README.en.md index c5efb71f10bcaede1335e3acd955a2ae806e75b2..7423f7aa98626f265d4fe2e55d1ee3b2383a65e4 100644 --- a/02.recognize_digits/README.en.md +++ b/02.recognize_digits/README.en.md @@ -259,6 +259,7 @@ def event_handler_plot(event): ``` `event_handler` is used to plot some text data when training. + ```python lists = [] diff --git a/02.recognize_digits/index.en.html b/02.recognize_digits/index.en.html index 45c85c8290baebb379c4f87a594230ee07836c2f..251ebb3232bc7b1cf92533f255cfa680f3befb71 100644 --- a/02.recognize_digits/index.en.html +++ b/02.recognize_digits/index.en.html @@ -301,6 +301,7 @@ def event_handler_plot(event): ``` `event_handler` is used to plot some text data when training. + ```python lists = [] diff --git a/03.image_classification/README.en.md b/03.image_classification/README.en.md index 0bb0775eaa3f689b4646e854cf5d6dd9f6d72263..2c243c62737cb217ec00df7103ac9b7b378e08d5 100644 --- a/03.image_classification/README.en.md +++ b/03.image_classification/README.en.md @@ -397,6 +397,34 @@ feeding={'image': 0, Callback function `event_handler` will be called during training when a pre-defined event happens. +`event_handler_plot`is used to plot a figure like below: + +![png](./image/train_and_test.png) + +```python +from paddle.v2.plot import Ploter + +train_title = "Train cost" +test_title = "Test cost" +cost_ploter = Ploter(train_title, test_title) + +step = 0 +def event_handler_plot(event): + global step + if isinstance(event, paddle.event.EndIteration): + if step % 1 == 0: + cost_ploter.append(train_title, step, event.cost) + cost_ploter.plot() + step += 1 + if isinstance(event, paddle.event.EndPass): + result = trainer.test( + reader=paddle.batch( + paddle.dataset.cifar.test10(), batch_size=128), + feeding=feeding) + cost_ploter.append(test_title, step, result.cost) +``` + +`event_handler` is used to plot some text data when training. ```python # event handler to track training and testing process @@ -422,7 +450,7 @@ Finally, we can invoke `trainer.train` to start training: trainer.train( reader=reader, num_passes=200, - event_handler=event_handler, + event_handler=event_handler_plot, feeding=feeding) ``` diff --git a/03.image_classification/README.md b/03.image_classification/README.md index e97cb3365591320bef7c2dd167a7b81fd79e46be..0eea28f906e1a63c1703c7d660e4bd9987df2a04 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -389,6 +389,35 @@ feeding={'image': 0, 可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。 +`event_handler_plot`可以用来利用回调数据来打点画图: + +![png](./image/train_and_test.png) + +```python +from paddle.v2.plot import Ploter + +train_title = "Train cost" +test_title = "Test cost" +cost_ploter = Ploter(train_title, test_title) + +step = 0 +def event_handler_plot(event): + global step + if isinstance(event, paddle.event.EndIteration): + if step % 1 == 0: + cost_ploter.append(train_title, step, event.cost) + cost_ploter.plot() + step += 1 + if isinstance(event, paddle.event.EndPass): + result = trainer.test( + reader=paddle.batch( + paddle.dataset.cifar.test10(), batch_size=128), + feeding=feeding) + cost_ploter.append(test_title, step, result.cost) +``` + +`event_handler` 用来在训练过程中输出文本日志 + ```python # End batch and end pass event handler def event_handler(event): @@ -413,7 +442,7 @@ def event_handler(event): trainer.train( reader=reader, num_passes=200, - event_handler=event_handler, + event_handler=event_handler_plot, feeding=feeding) ``` diff --git a/03.image_classification/image/train_and_test.png b/03.image_classification/image/train_and_test.png new file mode 100644 index 0000000000000000000000000000000000000000..c6336a9a69b95dc978719ce68896e3e752e67fed Binary files /dev/null and b/03.image_classification/image/train_and_test.png differ diff --git a/03.image_classification/index.en.html b/03.image_classification/index.en.html index 4e4b413ab81a5b14702b2338040f2ad60fc27f33..c28836ac766f49924fa10b56045de17178cde3e1 100644 --- a/03.image_classification/index.en.html +++ b/03.image_classification/index.en.html @@ -439,6 +439,34 @@ feeding={'image': 0, Callback function `event_handler` will be called during training when a pre-defined event happens. +`event_handler_plot`is used to plot a figure like below: + +![png](./image/train_and_test.png) + +```python +from paddle.v2.plot import Ploter + +train_title = "Train cost" +test_title = "Test cost" +cost_ploter = Ploter(train_title, test_title) + +step = 0 +def event_handler_plot(event): + global step + if isinstance(event, paddle.event.EndIteration): + if step % 1 == 0: + cost_ploter.append(train_title, step, event.cost) + cost_ploter.plot() + step += 1 + if isinstance(event, paddle.event.EndPass): + result = trainer.test( + reader=paddle.batch( + paddle.dataset.cifar.test10(), batch_size=128), + feeding=feeding) + cost_ploter.append(test_title, step, result.cost) +``` + +`event_handler` is used to plot some text data when training. ```python # event handler to track training and testing process @@ -464,7 +492,7 @@ Finally, we can invoke `trainer.train` to start training: trainer.train( reader=reader, num_passes=200, - event_handler=event_handler, + event_handler=event_handler_plot, feeding=feeding) ``` diff --git a/03.image_classification/index.html b/03.image_classification/index.html index 6c178be6bb8e4ae60ba033be1505101413636128..8678bde12918bbf847f810242041bd130be5cacb 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -431,6 +431,35 @@ feeding={'image': 0, 可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。 +`event_handler_plot`可以用来利用回调数据来打点画图: + +![png](./image/train_and_test.png) + +```python +from paddle.v2.plot import Ploter + +train_title = "Train cost" +test_title = "Test cost" +cost_ploter = Ploter(train_title, test_title) + +step = 0 +def event_handler_plot(event): + global step + if isinstance(event, paddle.event.EndIteration): + if step % 1 == 0: + cost_ploter.append(train_title, step, event.cost) + cost_ploter.plot() + step += 1 + if isinstance(event, paddle.event.EndPass): + result = trainer.test( + reader=paddle.batch( + paddle.dataset.cifar.test10(), batch_size=128), + feeding=feeding) + cost_ploter.append(test_title, step, result.cost) +``` + +`event_handler` 用来在训练过程中输出文本日志 + ```python # End batch and end pass event handler def event_handler(event): @@ -455,7 +484,7 @@ def event_handler(event): trainer.train( reader=reader, num_passes=200, - event_handler=event_handler, + event_handler=event_handler_plot, feeding=feeding) ```