我正在使用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 ()仅在启用急切执行后可用。
如何解决此问题?
答案 0 :(得分:0)
正如我在 TF 中看到的,这是因为 Keras、TF.keras 和 TF 版本问题。
tf.keras 和 keras Model 在保存和加载 Model(Cloning)时略有不同。