das icon indicating copy to clipboard operation
das copied to clipboard

AttributeError: module 'keras_tuner.oracles' has no attribute 'BayesianOptimization' when trying to run das.train_tune

Open avakiai opened this issue 9 months ago • 0 comments

Hi Jan,

I ran into an issue while trying to run the automatic architecture tuning using das.train_tune.

First, I got an error that keras-tuner was not installed. If it does not get installed as a requirement when installing/updating das, perhaps the doc can have a line with the install command?

After installing, I tried running it and got the following error. Is it a specific version of keras-tuner that's needed?

import das.train_tune

root_dir = '/data/das/v1'
data_dir = root_dir + '/dataset_v1'
dataset_dir = data_dir + '.npy'
models_dir = data_dir + '_kerastune.res'

model, params, tuner = das.train_tune.train(
    data_dir=dataset_dir,
    save_dir=models_dir,
    tune_config="/code/3_das/tuning.yml",
    log_messages=True,
)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], [line 8](vscode-notebook-cell:?execution_count=1&line=8)
      [5](vscode-notebook-cell:?execution_count=1&line=5) dataset_dir = data_dir + '.npy'
      [6](vscode-notebook-cell:?execution_count=1&line=6) models_dir = data_dir + '_kerastuner.res'
----> [8](vscode-notebook-cell:?execution_count=1&line=8) model, params, tuner = das.train_tune.train(
      [9](vscode-notebook-cell:?execution_count=1&line=9)     data_dir=dataset_dir,
     [10](vscode-notebook-cell:?execution_count=1&line=10)     save_dir=models_dir,
     [11](vscode-notebook-cell:?execution_count=1&line=11)     tune_config="/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/tuning.yml",
     [12](vscode-notebook-cell:?execution_count=1&line=12)     log_messages=True,
     [13](vscode-notebook-cell:?execution_count=1&line=13) )

File ~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:432, in train(data_dir, x_suffix, y_suffix, save_dir, save_prefix, save_name, model_name, nb_filters, kernel_size, nb_conv, use_separable, nb_hist, ignore_boundaries, batch_norm, nb_pre_conv, pre_nb_dft, pre_kernel_size, pre_nb_filters, upsample, dilations, nb_lstm_units, verbose, batch_size, nb_epoch, learning_rate, reduce_lr, reduce_lr_patience, fraction_data, seed, batch_level_subsampling, augmentations, tensorboard, wandb_api_token, wandb_project, wandb_entity, log_messages, nb_stacks, with_y_hist, balance, version_data, tune_config, nb_tune_trials, _qt_progress)
    [427](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:427) else:
    [428](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:428)     wandb = None
    [430](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:430) tuner = DasTuner(
    [431](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:431)     params=params,
--> [432](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:432)     oracle=kt.oracles.BayesianOptimization(
    [433](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:433)         objective=kt.Objective("val_loss", "min"),
    [434](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:434)         max_trials=nb_tune_trials,
    [435](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:435)     ),
    [436](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:436)     hypermodel=TunableModel(params, tune_config),
    [437](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:437)     overwrite=False,
    [438](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:438)     directory=save_dir,
    [439](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:439)     project_name=os.path.basename(save_name),
    [440](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:440)     tracker=wandb,
    [441](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:441) )
    [443](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:443) logger.info(tuner.search_space_summary())
    [444](https://vscode-remote+ssh-002dremote-002besi-002dsvhubx86-002d01-002eesi-002elocal.vscode-resource.vscode-cdn.net/mnt/cs/projects/BWFAFdeactivNpx/code/3_das/~/.conda/envs/das_forge/lib/python3.10/site-packages/das/train_tune.py:444) utils.save_params(params, save_name)

AttributeError: module 'keras_tuner.oracles' has no attribute 'BayesianOptimization'

Also, I noticed the documentation has a lot of new and interesting additions, but I am not sure what the latest/stable version of das is - I seem to recall the installation page previously having this information, but I can't find it there. I did notice keras-tuner is now pyproject file.

INFO:das.cli:  Linux-4.18.0-193.28.1.el8_2.x86_64-x86_64-with-glibc2.28
INFO:das.cli:  DAS v0.32.4
INFO:das.cli:     GUI is available.
INFO:das.cli:     xarray-behave v0.35.7
INFO:das.cli:     pyqtgraph v0.13.7
INFO:das.cli:     PySide6 v6.7.2
INFO:das.cli:     Qt v6.7.2
INFO:das.cli:
INFO:das.cli:  tensorflow v2.15.0
INFO:das.cli:  keras v2.15.0
INFO:das.cli:     GPU is not available.
INFO:das.cli:
INFO:das.cli:  python v3.10.15 | packaged by conda-forge | (main, Oct 16 2024, 01:24:24) [GCC 13.3.0]
INFO:das.cli:  pandas v2.2.3
INFO:das.cli:  numpy v1.26.4
INFO:das.cli:  h5py v3.12.1
INFO:das.cli:  scipy v1.14.1
INFO:das.cli:  scikit-learn v1.5.2
INFO:das.cli:  xarray v2024.10.0

Additionally, my env has the following keras-related packages:

keras                     2.15.0             pyhd8ed1ab_0    conda-forge
keras-tuner               1.4.7                    pypi_0    pypi
kernel-headers_linux-64   3.10.0              he073ed8_18    conda-forge
kt-legacy                 1.0.5                    pypi_0    pypi

Thanks!

avakiai avatar Apr 18 '25 13:04 avakiai