Talos-> TypeError:__init __()得到了意外的关键字参数'grid_downsample'

时间:2019-08-31 14:26:30

标签: talos

我正在尝试使用Talos运行超参数优化。由于要测试的参数很多,因此我想使用“ grid_downsample”参数,该参数将选择所有可能的超参数组合的30%。但是,当我运行代码时,我得到:TypeError: __init__() got an unexpected keyword argument 'grid_downsample'

我在没有'grid_downsample'选项且超参数较少的情况下测试了以下代码。

#load data
data = pd.read_csv('data.txt', sep="\t", encoding = "latin1")
# split into input (X) and output (y) variables
Y = np.array(data['Y'])
data_bis = data.drop(['Y'], axis = 1)
X = np.array(data_bis)

p = {'activation':['relu'],
     'optimizer': ['Nadam'],
     'first_hidden_layer': [12],
     'second_hidden_layer': [12],
     'batch_size': [20],
     'epochs': [10,20],
     'dropout_rate':[0.0, 0.2]}

def dnn_model(x_train, y_train, x_val, y_val, params):
    model = Sequential()
    #input layer
    model.add(Dense(params['first_hidden_layer'], input_shape=(1024,))) 
    model.add(Dropout(params['dropout_rate']))
    model.add(Activation(params['activation']))
    #hidden layer 2
    model.add(Dense(params['second_hidden_layer']))
    model.add(Dropout(params['dropout_rate']))
    model.add(Activation(params['activation']))
    # output layer with one node
    model.add(Dense(1))
    model.add(Activation(params['activation']))
    # Compile model
    model.compile(loss='binary_crossentropy', optimizer=params['optimizer'], metrics=['accuracy'])
    out = model.fit(x_train, y_train,
                    batch_size=params['batch_size'],
                    epochs=params['epochs'],
                    validation_data=[x_val, y_val],
                    verbose=0)

    return out, model

scan_object = ta.Scan(X, Y, model=dnn_model, params=p, experiment_name="test")

reporting = ta.Reporting(scan_object)
report = reporting.data
report.to_csv('./Random_search/dnn/report_talos.txt', sep = '\t')

此代码运行良好。如果我将scan_object的结尾更改为:scan_object = ta.Scan(X, Y, model=dnn_model, grid_downsample=0.3, params=p, experiment_name="test"),它会给我错误:TypeError: __init__() got an unexpected keyword argument 'grid_downsample',而我希望它的结果格式与普通网格搜索相同,但组合较少。我想念什么?参数名称是否更改?我在conda环境中使用Talos 0.6.3。 谢谢!

1 个答案:

答案 0 :(得分:1)

现在对您来说可能为时已晚,但他们已将其切换为fraction_limit。会给你这个

scan_object = ta.Scan(X, Y, model=dnn_model, params=p, experiment_name="test", fraction_limit = 0.1)

遗憾的是,该文档没有很好地更新

在GitHub上查看他们的示例: https://github.com/autonomio/talos/blob/master/examples/Hyperparameter%20Optimization%20with%20Keras%20for%20the%20Iris%20Prediction.ipynb