keras-tuner icon indicating copy to clipboard operation
keras-tuner copied to clipboard

Bayesian Crashes on 3rd Epoch each time.

Open STRATZ-Ken opened this issue 2 years ago • 6 comments

Traceback (most recent call last):
  File "/home/stratz/work/training/stratz-keras/win_rate.py", line 733, in <module>
    main()
  File "/home/stratz/work/training/stratz-keras/win_rate.py", line 730, in main
    model.train()
  File "/home/stratz/work/training/stratz-keras/neural_net.py", line 182, in train
    self.run_generator()
  File "/home/stratz/work/training/stratz-keras/neural_net.py", line 98, in run_generator
    tuner.search(training_generator,
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/engine/base_tuner.py", line 169, in search
    trial = self.oracle.create_trial(self.tuner_id)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/engine/oracle.py", line 189, in create_trial
    response = self.populate_space(trial_id)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 209, in populate_space
    self.gpr.fit(x, y)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 83, in fit
    self._alpha_vector = cho_solve(self._l_matrix, self._y_train)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 31, in cho_solve
    y = solve_triangular(l_matrix, b.reshape(-1, 1), lower=True)
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/keras_tuner/tuners/bayesian.py", line 24, in solve_triangular
    return tf.linalg.triangular_solve(a, b, lower=lower).numpy()
  File "/home/stratz/anaconda3/envs/stratz/lib/python3.9/site-packages/tensorflow/python/framework/ops.py", line 442, in __getattr__
    self.__getattribute__(name)
AttributeError: 'Tensor' object has no attribute 'numpy'

I do use a custom loss function. Not sure if that matters, saw a few posts on it.

STRATZ-Ken avatar Mar 01 '22 01:03 STRATZ-Ken

This was solved by enabling eager on the model, and not using accuracy but binary_accuracy.

STRATZ-Ken avatar Mar 01 '22 16:03 STRATZ-Ken

I'm having the same problem training a regression model - fails on the third round. Using tf 2.9.1 so eager is enabled by default, and I tried using both 'mse' and 'val_mse' and both fail.

jessegmeyerlab avatar Aug 18 '22 18:08 jessegmeyerlab

seems to be related to the num_initial_points parameter because after I change to 4 from the default of 2 it fails after 4 instead of 2

jessegmeyerlab avatar Aug 18 '22 19:08 jessegmeyerlab

@jessegmeyerlab Are you getting the same error message of AttributeError: 'Tensor' object has no attribute 'numpy'?

haifeng-jin avatar Aug 29 '22 18:08 haifeng-jin

@jessegmeyerlab Are you getting the same error message of AttributeError: 'Tensor' object has no attribute 'numpy'?

Yes

jessegmeyerlab avatar Aug 29 '22 19:08 jessegmeyerlab

@jessegmeyerlab It seems an important bug. Would you share a code snippet for us to reproduce the error? Thanks!

haifeng-jin avatar Aug 30 '22 03:08 haifeng-jin