From 13c6f692513771afb50e86a5de2d1cf9a3a53975 Mon Sep 17 00:00:00 2001 From: ruri Date: Thu, 25 Oct 2018 13:50:45 +0800 Subject: [PATCH] Remove utils plot until paddle support (#639) * Remove Utils until paddle support * delete figures until paddle support --- 01.fit_a_line/README.cn.md | 12 +++------ 01.fit_a_line/README.md | 14 ++++------- 01.fit_a_line/index.cn.html | 12 +++------ 01.fit_a_line/index.html | 14 ++++------- 01.fit_a_line/train.py | 13 ++++------ 02.recognize_digits/README.cn.md | 36 --------------------------- 02.recognize_digits/README.md | 34 +------------------------ 02.recognize_digits/index.cn.html | 36 --------------------------- 02.recognize_digits/index.html | 34 +------------------------ 03.image_classification/README.cn.md | 36 --------------------------- 03.image_classification/README.md | 32 ------------------------ 03.image_classification/index.cn.html | 36 --------------------------- 03.image_classification/index.html | 32 ------------------------ 05.recommender_system/README.cn.md | 20 ++++++--------- 05.recommender_system/README.md | 20 ++++++--------- 05.recommender_system/index.cn.html | 20 ++++++--------- 05.recommender_system/index.html | 20 ++++++--------- 17 files changed, 57 insertions(+), 364 deletions(-) diff --git a/01.fit_a_line/README.cn.md b/01.fit_a_line/README.cn.md index 428522c..8d1a8c7 100644 --- a/01.fit_a_line/README.cn.md +++ b/01.fit_a_line/README.cn.md @@ -196,28 +196,24 @@ feed_order=['x', 'y'] # Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" -# Plot data -from paddle.utils import Ploter train_title = "Train cost" test_title = "Test cost" -plot_cost = Ploter(train_title, test_title) step = 0 # event_handler prints training and testing info -def event_handler_plot(event): +def event_handler(event): global step if isinstance(event, EndStepEvent): if step % 10 == 0: # record a train cost every 10 batches - plot_cost.append(train_title, step, event.metrics[0]) + print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])) if step % 100 == 0: # record a test cost every 100 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) - plot_cost.append(test_title, step, test_metrics[0]) - plot_cost.plot() + print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0])) if test_metrics[0] < 10.0: # If the accuracy is good enough, we can stop the training. @@ -242,7 +238,7 @@ def event_handler_plot(event): trainer.train( reader=train_reader, num_epochs=100, - event_handler=event_handler_plot, + event_handler=event_handler, feed_order=feed_order) ``` diff --git a/01.fit_a_line/README.md b/01.fit_a_line/README.md index e6a1c84..13eef12 100644 --- a/01.fit_a_line/README.md +++ b/01.fit_a_line/README.md @@ -212,28 +212,24 @@ Moreover, an event handler is provided to print the training progress: # Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" -# Plot data -from paddle.utils import Ploter train_title = "Train cost" test_title = "Test cost" -plot_cost = Ploter(train_title, test_title) step = 0 # event_handler prints training and testing info -def event_handler_plot(event): +def event_handler(event): global step if isinstance(event, EndStepEvent): if step % 10 == 0: # record a train cost every 10 batches - plot_cost.append(train_title, step, event.metrics[0]) + print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])) + if step % 100 == 0: # record a test cost every 100 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) - plot_cost.append(test_title, step, test_metrics[0]) - plot_cost.plot() - if test_metrics[0] < 10.0: print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0])) + if test_metrics[0] < 10.0: # If the accuracy is good enough, we can stop the training. print('loss is less than 10.0, stop') trainer.stop() @@ -258,7 +254,7 @@ We now can start training by calling `trainer.train()`. trainer.train( reader=train_reader, num_epochs=100, - event_handler=event_handler_plot, + event_handler=event_handler, feed_order=feed_order) ``` diff --git a/01.fit_a_line/index.cn.html b/01.fit_a_line/index.cn.html index 138021a..e549995 100644 --- a/01.fit_a_line/index.cn.html +++ b/01.fit_a_line/index.cn.html @@ -238,28 +238,24 @@ feed_order=['x', 'y'] # Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" -# Plot data -from paddle.utils import Ploter train_title = "Train cost" test_title = "Test cost" -plot_cost = Ploter(train_title, test_title) step = 0 # event_handler prints training and testing info -def event_handler_plot(event): +def event_handler(event): global step if isinstance(event, EndStepEvent): if step % 10 == 0: # record a train cost every 10 batches - plot_cost.append(train_title, step, event.metrics[0]) + print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])) if step % 100 == 0: # record a test cost every 100 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) - plot_cost.append(test_title, step, test_metrics[0]) - plot_cost.plot() + print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0])) if test_metrics[0] < 10.0: # If the accuracy is good enough, we can stop the training. @@ -284,7 +280,7 @@ def event_handler_plot(event): trainer.train( reader=train_reader, num_epochs=100, - event_handler=event_handler_plot, + event_handler=event_handler, feed_order=feed_order) ``` diff --git a/01.fit_a_line/index.html b/01.fit_a_line/index.html index 7593fe9..744cbba 100644 --- a/01.fit_a_line/index.html +++ b/01.fit_a_line/index.html @@ -254,28 +254,24 @@ Moreover, an event handler is provided to print the training progress: # Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" -# Plot data -from paddle.utils import Ploter train_title = "Train cost" test_title = "Test cost" -plot_cost = Ploter(train_title, test_title) step = 0 # event_handler prints training and testing info -def event_handler_plot(event): +def event_handler(event): global step if isinstance(event, EndStepEvent): if step % 10 == 0: # record a train cost every 10 batches - plot_cost.append(train_title, step, event.metrics[0]) + print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])) + if step % 100 == 0: # record a test cost every 100 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) - plot_cost.append(test_title, step, test_metrics[0]) - plot_cost.plot() - if test_metrics[0] < 10.0: print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0])) + if test_metrics[0] < 10.0: # If the accuracy is good enough, we can stop the training. print('loss is less than 10.0, stop') trainer.stop() @@ -300,7 +296,7 @@ We now can start training by calling `trainer.train()`. trainer.train( reader=train_reader, num_epochs=100, - event_handler=event_handler_plot, + event_handler=event_handler, feed_order=feed_order) ``` diff --git a/01.fit_a_line/train.py b/01.fit_a_line/train.py index 5f99b0f..6077a16 100644 --- a/01.fit_a_line/train.py +++ b/01.fit_a_line/train.py @@ -69,26 +69,23 @@ feed_order = ['x', 'y'] # Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" -from paddle.utils import Ploter - train_title = "Train cost" test_title = "Test cost" -plot_cost = Ploter(train_title, test_title) step = 0 # event_handler prints training and testing info -def event_handler_plot(event): +def event_handler(event): global step if isinstance(event, EndStepEvent): if step % 10 == 0: # record a train cost every 10 batches - plot_cost.append(train_title, step, event.metrics[0]) + print("%s, Step %d, Cost %f" % + (train_title, step, event.metrics[0])) if step % 100 == 0: # record a test cost every 100 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) - plot_cost.append(test_title, step, test_metrics[0]) - plot_cost.plot() + print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0])) if test_metrics[0] < 10.0: # If the accuracy is good enough, we can stop the training. print('loss is less than 10.0, stop') @@ -106,7 +103,7 @@ def event_handler_plot(event): trainer.train( reader=train_reader, num_epochs=100, - event_handler=event_handler_plot, + event_handler=event_handler, feed_order=feed_order) diff --git a/02.recognize_digits/README.cn.md b/02.recognize_digits/README.cn.md index c21a3fa..144ecbb 100644 --- a/02.recognize_digits/README.cn.md +++ b/02.recognize_digits/README.cn.md @@ -321,42 +321,6 @@ def event_handler(event): lists.append((event.epoch, avg_cost, acc)) ``` -`event_handler_plot` 可以用来在训练过程中画图如下: - -
-
-图7 训练结果 -
- - -```python -from paddle.utils import Ploter - -train_title = "Train cost" -test_title = "Test cost" -cost_ploter = Ploter(train_title, test_title) -step = 0 -lists = [] - -# event_handler to plot a figure -def event_handler_plot(event): - global step - if isinstance(event, EndStepEvent): - if step % 100 == 0: - # event.metrics maps with train program return arguments. - # event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example. - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - # save parameters - trainer.save_params(params_dirname) - - avg_cost, acc = trainer.test( - reader=test_reader, feed_order=['img', 'label']) - cost_ploter.append(test_title, step, avg_cost) - lists.append((event.epoch, avg_cost, acc)) -``` #### 开始训练 diff --git a/02.recognize_digits/README.md b/02.recognize_digits/README.md index b32ba92..4423081 100644 --- a/02.recognize_digits/README.md +++ b/02.recognize_digits/README.md @@ -324,38 +324,6 @@ def event_handler(event): lists.append((event.epoch, avg_cost, acc)) ``` -`event_handler_plot` is used to plot a figure like below: - -![png](./image/train_and_test.png) - -```python -from paddle.utils import Ploter - -train_title = "Train cost" -test_title = "Test cost" -cost_ploter = Ploter(train_title, test_title) -step = 0 -lists = [] - -# event_handler to plot a figure -def event_handler_plot(event): - global step - if isinstance(event, EndStepEvent): - if step % 100 == 0: - # event.metrics maps with train program return arguments. - # event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example. - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - # save parameters - trainer.save_params(params_dirname) - - avg_cost, acc = trainer.test( - reader=test_reader, feed_order=['img', 'label']) - cost_ploter.append(test_title, step, avg_cost) - lists.append((event.epoch, avg_cost, acc)) -``` #### Start training @@ -365,7 +333,7 @@ Now that we setup the event_handler and the reader, we can start training the mo # Train the model now trainer.train( num_epochs=5, - event_handler=event_handler_plot, + event_handler=event_handler, reader=train_reader, feed_order=['img', 'label']) ``` diff --git a/02.recognize_digits/index.cn.html b/02.recognize_digits/index.cn.html index 55017f7..3b7df16 100644 --- a/02.recognize_digits/index.cn.html +++ b/02.recognize_digits/index.cn.html @@ -363,42 +363,6 @@ def event_handler(event): lists.append((event.epoch, avg_cost, acc)) ``` -`event_handler_plot` 可以用来在训练过程中画图如下: - -
-
-图7 训练结果 -
- - -```python -from paddle.utils import Ploter - -train_title = "Train cost" -test_title = "Test cost" -cost_ploter = Ploter(train_title, test_title) -step = 0 -lists = [] - -# event_handler to plot a figure -def event_handler_plot(event): - global step - if isinstance(event, EndStepEvent): - if step % 100 == 0: - # event.metrics maps with train program return arguments. - # event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example. - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - # save parameters - trainer.save_params(params_dirname) - - avg_cost, acc = trainer.test( - reader=test_reader, feed_order=['img', 'label']) - cost_ploter.append(test_title, step, avg_cost) - lists.append((event.epoch, avg_cost, acc)) -``` #### 开始训练 diff --git a/02.recognize_digits/index.html b/02.recognize_digits/index.html index 21a55a2..8121a46 100644 --- a/02.recognize_digits/index.html +++ b/02.recognize_digits/index.html @@ -366,38 +366,6 @@ def event_handler(event): lists.append((event.epoch, avg_cost, acc)) ``` -`event_handler_plot` is used to plot a figure like below: - -![png](./image/train_and_test.png) - -```python -from paddle.utils import Ploter - -train_title = "Train cost" -test_title = "Test cost" -cost_ploter = Ploter(train_title, test_title) -step = 0 -lists = [] - -# event_handler to plot a figure -def event_handler_plot(event): - global step - if isinstance(event, EndStepEvent): - if step % 100 == 0: - # event.metrics maps with train program return arguments. - # event.metrics[0] will yeild avg_cost and event.metrics[1] will yeild acc in this example. - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - # save parameters - trainer.save_params(params_dirname) - - avg_cost, acc = trainer.test( - reader=test_reader, feed_order=['img', 'label']) - cost_ploter.append(test_title, step, avg_cost) - lists.append((event.epoch, avg_cost, acc)) -``` #### Start training @@ -407,7 +375,7 @@ Now that we setup the event_handler and the reader, we can start training the mo # Train the model now trainer.train( num_epochs=5, - event_handler=event_handler_plot, + event_handler=event_handler, reader=train_reader, feed_order=['img', 'label']) ``` diff --git a/03.image_classification/README.cn.md b/03.image_classification/README.cn.md index 3652ed6..761eed3 100644 --- a/03.image_classification/README.cn.md +++ b/03.image_classification/README.cn.md @@ -383,42 +383,6 @@ test_reader = paddle.batch( 可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。 -`event_handler_plot`可以用来利用回调数据来打点画图: - -

-
-图12. 训练结果 -

- - -```python -params_dirname = "image_classification_resnet.inference.model" - -from paddle.utils 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, EndStepEvent): - if step % 1 == 0: - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - avg_cost, accuracy = trainer.test( - reader=test_reader, - feed_order=['pixel', 'label']) - cost_ploter.append(test_title, step, avg_cost) - - # save parameters - if params_dirname is not None: - trainer.save_params(params_dirname) -``` - `event_handler` 用来在训练过程中输出文本日志 ```python diff --git a/03.image_classification/README.md b/03.image_classification/README.md index fc58147..73cfe69 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -385,38 +385,6 @@ test_reader = paddle.batch( 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 -params_dirname = "image_classification_resnet.inference.model" - -from paddle.utils 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, EndStepEvent): - if step % 1 == 0: - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - avg_cost, accuracy = trainer.test( - reader=test_reader, - feed_order=['pixel', 'label']) - cost_ploter.append(test_title, step, avg_cost) - - # save parameters - if params_dirname is not None: - trainer.save_params(params_dirname) -``` - `event_handler` is used to plot some text data when training. ```python diff --git a/03.image_classification/index.cn.html b/03.image_classification/index.cn.html index 6278edb..da5aab5 100644 --- a/03.image_classification/index.cn.html +++ b/03.image_classification/index.cn.html @@ -425,42 +425,6 @@ test_reader = paddle.batch( 可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。 -`event_handler_plot`可以用来利用回调数据来打点画图: - -

-
-图12. 训练结果 -

- - -```python -params_dirname = "image_classification_resnet.inference.model" - -from paddle.utils 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, EndStepEvent): - if step % 1 == 0: - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - avg_cost, accuracy = trainer.test( - reader=test_reader, - feed_order=['pixel', 'label']) - cost_ploter.append(test_title, step, avg_cost) - - # save parameters - if params_dirname is not None: - trainer.save_params(params_dirname) -``` - `event_handler` 用来在训练过程中输出文本日志 ```python diff --git a/03.image_classification/index.html b/03.image_classification/index.html index fe6d7b9..71bde17 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -427,38 +427,6 @@ test_reader = paddle.batch( 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 -params_dirname = "image_classification_resnet.inference.model" - -from paddle.utils 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, EndStepEvent): - if step % 1 == 0: - cost_ploter.append(train_title, step, event.metrics[0]) - cost_ploter.plot() - step += 1 - if isinstance(event, EndEpochEvent): - avg_cost, accuracy = trainer.test( - reader=test_reader, - feed_order=['pixel', 'label']) - cost_ploter.append(test_title, step, avg_cost) - - # save parameters - if params_dirname is not None: - trainer.save_params(params_dirname) -``` - `event_handler` is used to plot some text data when training. ```python diff --git a/05.recommender_system/README.cn.md b/05.recommender_system/README.cn.md index ccd7286..0ea8bcc 100644 --- a/05.recommender_system/README.cn.md +++ b/05.recommender_system/README.cn.md @@ -439,30 +439,26 @@ feed_order = [ ```python # Specify the directory path to save the parameters params_dirname = "recommender_system.inference.model" - -from paddle.utils import Ploter -test_title = "Test cost" -plot_cost = Ploter(test_title) - - def event_handler(event): if isinstance(event, EndStepEvent): + test_reader = paddle.batch( + paddle.dataset.movielens.test(), batch_size=BATCH_SIZE) avg_cost_set = trainer.test( reader=test_reader, feed_order=feed_order) # get avg cost avg_cost = np.array(avg_cost_set).mean() - plot_cost.append(test_title, event.step, avg_cost_set[0]) - plot_cost.plot() - print("avg_cost: %s" % avg_cost) - print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, - float(avg_cost))) - if event.step == 20: # Adjust this number for accuracy + if float(avg_cost) < 4: # Change this number to adjust accuracy trainer.save_params(params_dirname) trainer.stop() + else: + print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, + float(avg_cost))) + if math.isnan(float(avg_cost)): + sys.exit("got NaN loss, training failed.") ``` ### 开始训练 diff --git a/05.recommender_system/README.md b/05.recommender_system/README.md index 5f3e395..7187093 100644 --- a/05.recommender_system/README.md +++ b/05.recommender_system/README.md @@ -415,30 +415,26 @@ For example, we can check the cost by `trainer.test` when `EndStepEvent` occurs # Specify the directory path to save the parameters params_dirname = "recommender_system.inference.model" -from paddle.utils import Ploter -test_title = "Test cost" -plot_cost = Ploter(test_title) - - def event_handler(event): if isinstance(event, EndStepEvent): + test_reader = paddle.batch( + paddle.dataset.movielens.test(), batch_size=BATCH_SIZE) avg_cost_set = trainer.test( reader=test_reader, feed_order=feed_order) # get avg cost avg_cost = np.array(avg_cost_set).mean() - plot_cost.append(test_title, event.step, avg_cost_set[0]) - plot_cost.plot() - print("avg_cost: %s" % avg_cost) - print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, - float(avg_cost))) - if event.step == 20: # Adjust this number for accuracy + if float(avg_cost) < 4: # Change this number to adjust accuracy trainer.save_params(params_dirname) trainer.stop() - + else: + print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, + float(avg_cost))) + if math.isnan(float(avg_cost)): + sys.exit("got NaN loss, training failed.") ``` ### Training diff --git a/05.recommender_system/index.cn.html b/05.recommender_system/index.cn.html index 3c9f63f..974725d 100644 --- a/05.recommender_system/index.cn.html +++ b/05.recommender_system/index.cn.html @@ -481,30 +481,26 @@ feed_order = [ ```python # Specify the directory path to save the parameters params_dirname = "recommender_system.inference.model" - -from paddle.utils import Ploter -test_title = "Test cost" -plot_cost = Ploter(test_title) - - def event_handler(event): if isinstance(event, EndStepEvent): + test_reader = paddle.batch( + paddle.dataset.movielens.test(), batch_size=BATCH_SIZE) avg_cost_set = trainer.test( reader=test_reader, feed_order=feed_order) # get avg cost avg_cost = np.array(avg_cost_set).mean() - plot_cost.append(test_title, event.step, avg_cost_set[0]) - plot_cost.plot() - print("avg_cost: %s" % avg_cost) - print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, - float(avg_cost))) - if event.step == 20: # Adjust this number for accuracy + if float(avg_cost) < 4: # Change this number to adjust accuracy trainer.save_params(params_dirname) trainer.stop() + else: + print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, + float(avg_cost))) + if math.isnan(float(avg_cost)): + sys.exit("got NaN loss, training failed.") ``` ### 开始训练 diff --git a/05.recommender_system/index.html b/05.recommender_system/index.html index 512f5f4..403da9f 100644 --- a/05.recommender_system/index.html +++ b/05.recommender_system/index.html @@ -457,30 +457,26 @@ For example, we can check the cost by `trainer.test` when `EndStepEvent` occurs # Specify the directory path to save the parameters params_dirname = "recommender_system.inference.model" -from paddle.utils import Ploter -test_title = "Test cost" -plot_cost = Ploter(test_title) - - def event_handler(event): if isinstance(event, EndStepEvent): + test_reader = paddle.batch( + paddle.dataset.movielens.test(), batch_size=BATCH_SIZE) avg_cost_set = trainer.test( reader=test_reader, feed_order=feed_order) # get avg cost avg_cost = np.array(avg_cost_set).mean() - plot_cost.append(test_title, event.step, avg_cost_set[0]) - plot_cost.plot() - print("avg_cost: %s" % avg_cost) - print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, - float(avg_cost))) - if event.step == 20: # Adjust this number for accuracy + if float(avg_cost) < 4: # Change this number to adjust accuracy trainer.save_params(params_dirname) trainer.stop() - + else: + print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1, + float(avg_cost))) + if math.isnan(float(avg_cost)): + sys.exit("got NaN loss, training failed.") ``` ### Training -- GitLab