autonomio / talos

Hyperparameter Experiments with TensorFlow and Keras
https://autonom.io
MIT License
1.62k stars 268 forks source link

__init__() got an unexpected keyword argument 'dataset_name' #305

Closed kenfus closed 5 years ago

kenfus commented 5 years ago

Thanks so much for coming here to raise an issue. Please take a moment to 'check' the below boxes:

If you still have an error, please submit complete trace and a code with:

You can provide the code in pastebin / gist or any other format you like.


The code works flawlessly without the dataset_name and the experiment_no.

I have no idea what the issue could be! Thanks so much for making Talos.

TypeError                                 Traceback (most recent call last)

<ipython-input-8-ce880ac8d012> in <module>()
     79 t = ta.Scan(x=X_train, y=y_train, params = p, model=get_model,
     80             dataset_name='task_3',
---> 81             experiment_no='1')

TypeError: __init__() got an unexpected keyword argument 'dataset_name'
# https://towardsdatascience.com/hyperparameter-optimization-with-keras-b82e6364ca53
# Function to create model, required for KerasClassifier
def get_model(x_train, y_train, x_val, y_val, params):
# create model

    #parameters defined
    lr = params['lr']
    epochs= params['epochs']
    neurons = params['neurons']
    optimizer = params['optimizer']
    loss= params['loss']
    decay = params['decay']
    momentum=params['momentum']
    batch_size = params['batch_size']
    dropout_rate = params['dropout']

    input_shape = X_train.shape[1]

    model = Sequential()
    model.add(Dense(neurons, input_shape = (input_shape,))),
    model.add(LeakyReLU(alpha=0.01)),
    model.add(BatchNormalization()),

    model.add(Dropout(dropout_rate, seed=42)),
    model.add(Dense(neurons)),
    model.add(LeakyReLU(alpha=0.01)),
    model.add(BatchNormalization()),

    model.add(Dropout(dropout_rate, seed=42)),
    model.add(Dense(neurons)),
    model.add(LeakyReLU(alpha=0.01)),
    model.add(BatchNormalization()),

    model.add(Dropout(dropout_rate, seed=42)),
    model.add(Dense(neurons)),
    model.add(LeakyReLU(alpha=0.01)),
    model.add(BatchNormalization()),

    model.add(Dropout(dropout_rate, seed=42)),
    model.add(Dense(neurons)),
    model.add(LeakyReLU(alpha=0.01)),
    model.add(BatchNormalization()),

    model.add(Dropout(dropout_rate, seed=42)),
    model.add(Dense(5, activation='softmax'))
    # Compile model

    # https://stackoverflow.com/questions/54377668/talosreturnerror-talos-make-sure-that-input-model-returns-out-model-model-f

    if optimizer=="Adam":
            opt=keras.optimizers.Adam(lr=lr, beta_1=0.9, beta_2=0.999)
    if optimizer=="Adagrad":
            opt=keras.optimizers.Adagrad(lr=lr, epsilon=None, decay=decay)
    if optimizer=="sgd":
            opt=keras.optimizers.SGD(lr=lr, momentum=momentum, decay=decay, nesterov=False)

    model.compile(loss=loss,optimizer=opt,
                 metrics=['accuracy'])

    history = model.fit(x = x_train, y= y_train, validation_data=[x_val, y_val], 
                        epochs=params['epochs'], batch_size = batch_size,verbose=1)

    return history, model

p = {'lr': [0.0001],
      'neurons':[1200,1500],
      'decay':[0],
      'optimizer': ["Adam"],
      'hidden_layers':[3],
      'momentum': [0.0],
      'batch_size': [128],
      'loss': ["sparse_categorical_crossentropy"],
      'epochs': [250],
      'dropout': [0.2,0.3]}

t = ta.Scan(x=X_train, y=y_train, params = p, model=get_model,
            dataset_name='task_3',
            experiment_no='1')
mikkokotila commented 5 years ago

It's called experiment_name in the recent versions. Try that instead. It replaces dataset_name and experiment_no. Closing here.

fairread commented 4 years ago

Hi @mikkokotila many thanks for developing Talos! It's really helpful for my classifier development.

Anyway thanks also to you and @kenfus for pointing out this issue which I also am facing it. Think such info could probably be updated in Talos docs here. Thanks again.

surendramehra commented 4 years ago

I have train the model and showing like Exception: Could not initialize MemoizationPolicy. init() got an unexpected keyword argument 'epochs' how can resolve this

maksudcs commented 4 years ago

@surendramehra I got this same error.

Exception: Could not initialize MemoizationPolicy. __init__() got an unexpected keyword argument 'epochs'

but when i add policy -name: TEDPolicy into config.yml then error solved.

policies:
  - name: MemoizationPolicy
  - name: TEDPolicy
    max_history: 5
    epochs: 100
  - name: KerasPolicy
  - name: MappingPolicy
  - name: FormPolicy