Repository: keras-team/autokeras

Issue:
Exception occurred at train() : Input contains NaN, infinity or a value too large for dtype('float32').  when run example/task_modules/image/cnn_mnist_regression.py 
 

### Bug Description
I try to run  'example/task_modules/image/cnn_mnist_regression.py'
but this exception happens:

Exception occurred at train() : Input contains NaN, infinity or a value too large for dtype('float32').
 
 ### Expected Behavior
Traceback (most recent call last):
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/autokeras/search.py", line 343, in train
    verbose=verbose).train_model(**trainer_args)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/autokeras/nn/model_trainer.py", line 138, in train_model
    test_loss, metric_value = self._test()
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/autokeras/nn/model_trainer.py", line 216, in _test
    return test_loss, self.metric.compute(all_predicted, all_targets)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/autokeras/nn/metric.py", line 47, in compute
    return cls.evaluate(prediction, target)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/autokeras/nn/metric.py", line 51, in evaluate
    return mean_squared_error(target, prediction)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/sklearn/metrics/regression.py", line 239, in mean_squared_error
    y_true, y_pred, multioutput)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/sklearn/metrics/regression.py", line 77, in _check_reg_targets
    y_pred = check_array(y_pred, ensure_2d=False)
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/sklearn/utils/validation.py", line 573, in check_array
    allow_nan=force_all_finite == 'allow-nan')
  File "/home/ukxu/anaconda3/envs/ak/lib/python3.6/site-packages/sklearn/utils/validation.py", line 56, in _assert_all_finite
    raise ValueError(msg_err.format(type_err, X.dtype))
ValueError: Input contains NaN, infinity or a value too large for dtype('float32').

### Setup Details
Include the details about the versions of:
 - OS type and version:
 - Python:                  3.6.8
 - autokeras:              0.3.6
 - scikit-learn:            0.20.1
 - numpy:
 - keras:                     2.2.4
 - scipy:
 - tensorflow:            1.12.0 
 - pytorch:                 0.4.1

### Additional context
<!---
Add any other context about the problem here.
-->



Discussion:

Resolving patch:
diff --git a/autokeras/nn/model_trainer.py b/autokeras/nn/model_trainer.py
--- a/autokeras/nn/model_trainer.py
+++ b/autokeras/nn/model_trainer.py
@@ -110,12 +110,14 @@ def __init__(self, model, path, **kwargs):
         self.temp_model_path = os.path.join(path, 'temp_model')
 
     def train_model(self,
+                    lr=0.001,
                     max_iter_num=None,
                     max_no_improvement_num=None,
                     timeout=None):
         """Train the model.
         Train the model with max_iter_num or max_no_improvement_num is met.
         Args:
+            lr: learning rate of the traininig
             timeout: timeout in seconds
             max_iter_num: An integer. The maximum number of epochs to train the model.
                 The training will stop when this number is reached.
@@ -138,7 +140,7 @@ def train_model(self,
         test_loss_list = []
         self.optimizer = torch.optim.SGD(
             self.model.parameters(),
-            0.025,
+            lr=lr,
             momentum=0.9,
             weight_decay=3e-4)
         # self.optimizer = torch.optim.Adam(self.model.parameters())


Test patch: