Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not interpret optimizer identifier: <keras.src.optimizers.adam.Adam object #64250

Closed
hilmyas opened this issue Mar 22, 2024 · 4 comments
Closed
Assignees
Labels
comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author type:docs-bug Document issues

Comments

@hilmyas
Copy link

hilmyas commented Mar 22, 2024

Issue type

Documentation Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

2.16.1

Custom code

No

OS platform and distribution

No response

Mobile device

No response

Python version

No response

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Some days ago, I tried to run codes by using Google Colab from a tutorial of transfer learning with movinet without any error. Today, I tried to run codes by using Google Colab from the same tutorial and it produced error when I tried to compile the model.

`num_epochs = 2

loss_obj = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)

optimizer = tf.keras.optimizers.Adam(learning_rate = 0.001)

model.compile(loss=loss_obj, optimizer=optimizer, metrics=['accuracy'])`

Standalone code to reproduce the issue

https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/video/transfer_learning_with_movinet.ipynb#scrollTo=dVqBLrn1tBsd

Relevant log output

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-0c295092a661> in <cell line: 7>()
      5 optimizer = tf.keras.optimizers.Adam(learning_rate = 0.001)
      6 
----> 7 model.compile(loss=loss_obj, optimizer=optimizer, metrics=['accuracy'])

/usr/local/lib/python3.10/dist-packages/tf_keras/src/utils/traceback_utils.py in error_handler(*args, **kwargs)
     68             # To get the full stack trace, call:
     69             # `tf.debugging.disable_traceback_filtering()`
---> 70             raise e.with_traceback(filtered_tb) from None
     71         finally:
     72             del filtered_tb

/usr/local/lib/python3.10/dist-packages/tf_keras/src/optimizers/__init__.py in get(identifier, **kwargs)
    333         )
    334     else:
--> 335         raise ValueError(
    336             f"Could not interpret optimizer identifier: {identifier}"
    337         )

ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.adam.Adam object at 0x7af7a01536d0>
@google-ml-butler google-ml-butler bot added type:bug Bug type:docs-bug Document issues labels Mar 22, 2024
@tilakrayal tilakrayal added comp:keras Keras related issues and removed type:bug Bug labels Mar 22, 2024
@tilakrayal
Copy link
Contributor

tilakrayal commented Mar 22, 2024

@hilmyas,
By default Tensorflow v2.16 uses keras v3.0 which might be the reason for the error you are facing. As the work-around, Could you please try to install keras 2 where the code was executed without any issue/error. Kindly find the gist of it here.

!pip install -U tf_keras # Keras 2
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"

Thank you!

@tilakrayal tilakrayal added the stat:awaiting response Status - Awaiting response from author label Mar 22, 2024
@hilmyas
Copy link
Author

hilmyas commented Mar 23, 2024

It works. Thanks for your help.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Mar 23, 2024
@tilakrayal
Copy link
Contributor

@hilmyas,
Glad the issue is resolved for you, Could you please feel free to move this issue to closed status. Thank you!

@tilakrayal tilakrayal added the stat:awaiting response Status - Awaiting response from author label Mar 23, 2024
@hilmyas hilmyas closed this as completed Mar 23, 2024
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:keras Keras related issues stat:awaiting response Status - Awaiting response from author type:docs-bug Document issues
Projects
None yet
Development

No branches or pull requests

2 participants