shenweichen / DeepCTR

Easy-to-use,Modular and Extendible package of deep-learning based CTR models .
https://deepctr-doc.readthedocs.io/en/latest/index.html
Apache License 2.0
7.59k stars 2.22k forks source link

ValueError: Could not interpret optimizer identifier: <keras.optimizers.optimizer_v2.adam.Adam object at 0x7fbe77391a00> #486

Open ChildishChange opened 2 years ago

ChildishChange commented 2 years ago

Describe the bug(问题描述) get a valueError when running deepfm demo

To Reproduce(复现步骤)

# fail and get ValueError: Could not interpret optimizer identifier: <keras.optimizers.optimizer_v2.adam.Adam object at 0x7fbe77391a00>
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=learning_rate),
                loss="binary_crossentropy",
                metrics=['accuracy','binary_crossentropy', tf.keras.metrics.AUC(curve='ROC')])

# success
model.compile("adam", "binary_crossentropy",
                metrics=['accuracy','binary_crossentropy',tf.keras.metrics.AUC(curve='ROC')], )

Operating environment(运行环境):

Additional context

solution may be: https://stackoverflow.com/questions/70658010/could-not-interpret-optimizer-identifier-formatidentifier

zanshuxun commented 2 years ago

try this: https://deepctr-doc.readthedocs.io/en/latest/FAQ.html#set-learning-rate-and-use-earlystopping

ChildishChange commented 2 years ago

try this: https://deepctr-doc.readthedocs.io/en/latest/FAQ.html#set-learning-rate-and-use-earlystopping

also failed, XP

# ImportError: cannot import name 'Adam' from 'tensorflow.python.keras.optimizers' (/root/miniconda3/envs/py3_tf2/lib/python3.8/site-packages/tensorflow/python/keras/optimizers.py)
from tensorflow.python.keras.optimizers import Adam,Adagrad
includeno commented 1 year ago

Tensorflow 2.10.0版本

from tensorflow.python.keras.optimizers import adam_v2
adam=adam_v2.Adam()
print(adam)
print(adam.get_config())
# <tensorflow.python.keras.optimizer_v2.adam.Adam object at 0x1011329d0>
# {'name': 'Adam', 'learning_rate': 0.001, 'decay': 0.0, 'beta_1': 0.9, 'beta_2': 0.999, 'epsilon': 1e-07, 'amsgrad': False}

from tensorflow.python.keras.optimizers import Adam
adam_old=Adam()
print(adam_old)#ImportError: cannot import name 'Adam' from 'tensorflow.python.keras.optimizers'
print(adam_old.get_config())
chentao169 commented 1 year ago

model.compile(optimizer='adam', loss=tf.keras.losses.BinaryCrossentropy(), metrics=metrics) This works for me