【问题标题】:Module object is not callable (kerastuner)模块对象不可调用(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))

【问题讨论】:

    标签: python-3.x keras module keras-tuner


    【解决方案1】:

    我发现我导入了错误的随机搜索和超参数。

    【讨论】:

      猜你喜欢
      • 2017-06-17
      • 2012-09-28
      • 2014-09-21
      • 2022-01-09
      • 2011-05-30
      • 2021-11-22
      • 1970-01-01
      相关资源
      最近更新 更多