gpt4 book ai didi

tf.keras - ValueError : Could not interpret optimizer identifier:

转载 作者:行者123 更新时间:2023-12-05 00:58:19 28 4
gpt4 key购买 nike

我尝试运行这段代码,但我遇到了这个错误,请任何人过去也遇到过同样的错误:

sgd = optimizers.SGD(lr = 0.01, decay = 1e-6, momentum = 0.9, nesterov = True)

编译模型

model.compile(optimizer = sgd, loss = OBJECTIVE_FUNCTION, metrics = LOSS_METRICS)
fit_history = model.fit_generator(
train_generator,
steps_per_epoch=STEPS_PER_EPOCH_TRAINING,
epochs = NUM_EPOCHS,
validation_data=validation_generator,
validation_steps=STEPS_PER_EPOCH_VALIDATION,
callbacks=[cb_checkpointer, cb_early_stopper]
)
model.load_weights("../working/best.hdf5")

现在我有这个错误:

File "", line 1, in runfile('C:/Users/ResNet50VF72.py', wdir='C:/Users/RESNET')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/RESNET/ResNet50VF72.py", line 110, in model.compile(optimizer = sgd, loss = OBJECTIVE_FUNCTION, metrics = LOSS_METRICS)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 96, in compile self.optimizer = optimizers.get(optimizer)
File "C:\ProgramData\Anaconda3\lib\site-packages\keras\optimizers.py", line 793, in get str(identifier))
ValueError: Could not interpret optimizer identifier : <tensorflow.python.keras.optimizers.SGD object at 0x0000013887021208>

最佳答案

我在使用另一个优化器时遇到了同样的问题:

ValueError: Could not interpret optimizer identifier: <tensorflow.python.keras.optimizers.Adam object at 0x7f3fc4575ef0>

这是因为我使用 keras 而不是 tensorflow.keras 创建了我的模型,所以解决方案是从:

from keras.models import Sequential

from tensorflow.keras.models import Sequential

或者也可以只使用 keras 而不是 tensorflow.keras(我混合了新旧代码),似乎是两者的混合导致了问题(这不足为奇)。

关于tf.keras - ValueError : Could not interpret optimizer identifier: <tensorflow. python.keras.optimizers.SGD 对象位于 0x0000013887021208>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58272318/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com