gpt4 book ai didi

python-3.x - 未实现错误 : __deepcopy__() is only available when eager execution is enabled

转载 作者:行者123 更新时间:2023-12-05 07:23:45 26 4
gpt4 key购买 nike

我正在使用 GridSearchCV 来调整我的 LSTM 模型的超参数:

def compile_lstm(self):



'''create the layers'''

self.model = keras.models.Sequential()
self.model.add(keras.layers.LSTM(50))
self.model.add(keras.layers.Dense(1, activation='softmax'))
self.model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['acc'])

model = KerasClassifier(build_fn=self.model, verbose=0)
# define the grid search parameters
batch_size = [10, 20, 40, 60, 80, 100]
epochs = [10, 50, 100]
param_grid = dict(batch_size=batch_size, epochs=epochs)
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)
X = self.X
Y = self.Y
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.20, random_state=42)
grid_result = grid.fit(X, Y)
# summarize results
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
print("%f (%f) with: %r" % (mean, stdev, param))

但我收到以下错误:

NotImplementedError:deepcopy() 仅在启用急切执行时可用。

我该如何解决这个问题??

最佳答案

正如我在 TF 中看到的那样,这是因为 Keras、TF.keras 和 TF 版本问题。

tf.keras 和 keras 模型在保存和加载模型(克隆)时略有不同。

这可能对您有帮助:https://stackoverflow.com/a/52728435/9273317

关于python-3.x - 未实现错误 : __deepcopy__() is only available when eager execution is enabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55808426/

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