模块对象不可调用(kerastuner)
Posted
技术标签:
【中文标题】模块对象不可调用(kerastuner)【英文标题】:Module object is not callable (kerastuner) 【发布时间】:2021-12-26 00:02:58 【问题描述】:我正在尝试使用 kerastuner 优化我的 keras NN,但由于某种原因,它在 Tuner=randomsearch 行上给了我一个“模块”对象不可调用错误。
import pandas as pd
import numpy as np
from sklearn.preprocessing import scale
from keras.models import Sequential
from keras.layers import Dense
from sklearn.metrics import mean_squared_error
from matplotlib import pyplot as plt
from keras_tuner.tuners import randomsearch
from keras_tuner.engine import hyperparameters
import time
LOG_DIR = f"int(time.time())"
def build_model(hp):
model = Sequential()
model.add(Dense(hp.Int("input_units", min_value=1, max_value=105, step=1), input_dim=X_train.shape[1], activation='relu'))
for i in range(hp.Int("n_layers", 1, 5)):
model.add(Dense(hp.Int(f"conv_i_units", min_value=1, max_value=105, step=1), activation='relu'))
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
return model
tuner = randomsearch(build_model, objective = "val_accuracy", max_trials = 1, executions_per_trial = 1, directory = LOG_DIR)
tuner.search(x=X_train, y=y_train, epochs=1, batch_size=146, validation_data=(X_test, y_test))
【问题讨论】:
【参考方案1】:我发现我导入了错误的随机搜索和超参数。
【讨论】:
以上是关于模块对象不可调用(kerastuner)的主要内容,如果未能解决你的问题,请参考以下文章