giuseppegrieco / keras-tuner-cv

Extension for keras tuner that adds a set of classes to implement cross validation techniques.
GNU General Public License v3.0
5 stars 5 forks source link

cannot import name 'tuner_utils' from 'keras_tuner.engine' #11

Closed senyang1107 closed 6 months ago

senyang1107 commented 6 months ago

Hellow, when I excitedly installed keras-tuner-cv and prepared to perform K-fold verification on the hyperparameters to improve the generalization ability of the model, I failed in the first step. Specifically, when I run from keras_tuner_cv.outer_cv import OuterCV, I get the following error : in this line:from keras_tuner.engine import tuner_utils ImportError: cannot import name 'tuner_utils' from 'keras_tuner.engine' (D:\Anaconda\envs\py310\lib\site-packages\keras_tuner\engine__init__.py). My version of kerastuner is 1.0.5. and tensorflow-gpu was 2.9.0.

VZoche-Golob commented 6 months ago

Perhaps you should try more recent versions of kerastuner (specifically version 1.1.3) and tensorflow. See also this comment and the following statement in this pull request:

limit the tuner version to version 1.1.3 with which keras-tuner-cv works

If you want to use kerastuner v1.3.5, I suggest to use this fork until it is merged to the main repo see comment.

senyang1107 commented 6 months ago

也许您应该尝试更新版本的 kerastuner(特别是 1.1.3 版)和 tensorflow。另请参阅此拉取请求中的此注释和以下语句:

将调谐器版本限制为 keras-tuner-cv 使用的版本 1.1.3

如果你想使用 kerastuner v1.3.5,我建议使用这个分支,直到它被合并到主存储库中,请参阅评论

Thank you very much. I have successfully imported OuterCV, but another problem occurs after running it, as follows: AttributeError: 'InnerCV' object has no attribute '_display' File D:\Anaconda\envs\py310\lib\site-packages\keras_tuner_cv\inner_cv.py:286, in inner_cv..InnerCV.__save_output(self, model, x, filename) 282 def __save_output(self, model, x, filename): 283 y = model.predict( 284 x, 285 batch_size=len(x),

--> 286 verbose=self._display.verbose,

287     )
288     with open(
289         filename,
290         "wb",
291     ) as fp:
292         np.save(fp, y)
VZoche-Golob commented 6 months ago

Which versions of keras-tuner and of keras-tuner-cv are you using?

senyang1107 commented 6 months ago

Thank you very much for your reply. I have reviewed the previous comments and also checked the versions of my own keras_tuner and keras_tuneer_cv, and found that they are versions 1.1.3 and 1.0.3, respectively. Therefore, version upgrades should be mentioned. However, during the process of upgrading keras_tuneer_cv, I found that version 1.1 could not be found. mmexport1712157784040 mmexport1712162417353

VZoche-Golob commented 6 months ago

More recent versions than 1.0.3 of keras-tuner-cv have to be installed directly from github as they are not "released" but only suggested versions in forks different from the main branch. I doubt that suggested version 1.1 is compatible to keras-tuner < 1.3.5 and it is not tested with keras-tuner > 1.3.5.

Those versions are development versions. You are using this software at your own risk.

See e.g. https://stackoverflow.com/questions/13685920/install-specific-git-commit-with-pip and https://pythonassets.com/posts/how-to-pip-install-from-a-git-repository/ for instructions to install from GitHub using pip.

senyang1107 commented 6 months ago

More recent versions than 1.0.3 of keras-tuner-cv have to be installed directly from github as they are not "released" but only suggested versions in forks different from the main branch. I doubt that suggested version 1.1 is compatible to keras-tuner < 1.3.5 and it is not tested with keras-tuner > 1.3.5.

Those versions are development versions. You are using this software at your own risk.

See e.g. https://stackoverflow.com/questions/13685920/install-specific-git-commit-with-pip and https://pythonassets.com/posts/how-to-pip-install-from-a-git-repository/ for instructions to install from GitHub using pip.

Thank you very much for your guidance. In summary, I first upgraded the kerastuner version to 1.3.5, which was able to successfully import Keras_tuner_cv, and then two problems appeared (a) 'InnerCV' object has no attribute '_display' (b) convert_to_metrics_dict() takes 2 positional arguments but 3 were given were solved by installing Keras_tuner_cv version 1.1, but a new GPU problem(Best val_loss So Far: None) appeared. The strange thing is that I saw that you mentioned that the GPU problem had been fixed. I felt very strange about this situation. Is there something wrong with the development version I installed? 屏幕截图 2024-04-04 231529

VZoche-Golob commented 6 months ago

Using Tensorflow 2.13.0, numpy 1.24.3, keras-tuner 1.3.5 and keras-tuner-cv 1.1.1, I cannot reproduce your issue. In my projects, it works fine. In none of the tests in inner_cv_test.py and in none of the examples (inner_cv.py, outer_cv.py, inner_cv_without_gpu.py), this issue occurs.

Which software versions are you using? Can you please provide an example (code and data) where the issue occurs?

senyang1107 commented 6 months ago

Using Tensorflow 2.13.0, numpy 1.24.3, keras-tuner 1.3.5 and keras-tuner-cv 1.1.1, I cannot reproduce your issue. In my projects, it works fine. In none of the tests in inner_cv_test.py and in none of the examples (inner_cv.py, outer_cv.py, inner_cv_without_gpu.py), this issue occurs.

Which software versions are you using? Can you please provide an example (code and data) where the issue occurs?

Thank you very much for the keras_tuner_cv (version:1.1.1) you provided, which effectively solves this problem, so for now, (a) kerastuner: v 1.3.5 (b) keras_tuner_cv: v 1.1.1 (c) tensorflow-gpu: v 2.9.0 able to run keras_tuner_cv perfectly. Thank you again for your answers to the above questions !!!

VZoche-Golob commented 6 months ago

You're welcome. Could you please close the issue as your problem is solved?