简体   繁体   中英

Talos --> TypeError: __init__() got an unexpected keyword argument 'grid_downsample'

I am trying to run a hyperparameters optimization with Talos. As I have a lot of parameters to test, I want to use a 'grid_downsample' argument that will select 30% of all possible hyperparameters combinations. However when I run my code I get: TypeError: __init__() got an unexpected keyword argument 'grid_downsample'

I tested the code below without the 'grid_downsample' option and with less hyperparameters.

#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')

This code works well. If I change the scan_object as the end to: scan_object = ta.Scan(X, Y, model=dnn_model, grid_downsample=0.3, params=p, experiment_name="test") , it gives me the error: TypeError: __init__() got an unexpected keyword argument 'grid_downsample' while I was expecting to have the same results format as a normal grid search but with less combinations. What am I missing? Did the name of the argument change? I'm using Talos 0.6.3 in a conda environment. Thank you!

might be too late for you now but they've switched it to fraction_limit. It would give this for you

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

Sadly, the doc isn't well updated

Check out their examples on GitHub: https://github.com/autonomio/talos/blob/master/examples/Hyperparameter%20Optimization%20with%20Keras%20for%20the%20Iris%20Prediction.ipynb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM