Skip to content

Instantly share code, notes, and snippets.

@mikkokotila
Last active November 21, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mikkokotila/4c0d6298ff0a22dc561fb387a1b4b0bb to your computer and use it in GitHub Desktop.
Save mikkokotila/4c0d6298ff0a22dc561fb387a1b4b0bb to your computer and use it in GitHub Desktop.
import talos
from keras.models import Sequential
from keras.layers import Dense
def minimal():
x, y = talos.templates.datasets.iris()
p = {'activation':['relu', 'elu'],
'optimizer': ['Nadam', 'Adam'],
'losses': ['categorical_crossentropy'],
'batch_size': [20,30,40],
'epochs': [10,20]}
def iris_model(x_train, y_train, x_val, y_val, params):
model = Sequential()
model.add(Dense(32, input_dim=4, activation=params['activation']))
model.add(Dense(3, activation='softmax'))
model.compile(optimizer=params['optimizer'], loss=params['losses'])
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 = talos.Scan(x, y, model=iris_model, params=p, experiment_name='iris', fraction_limit=0.1)
return scan_object
@edgardmota
Copy link

I've only made a call to the function minimal() and I'm getting the following:

File "minimal_talos_example.py", line 26, in iris_model
    validation_data=[x_val, y_val])
  File "/home/edgardm/.local/share/virtualenvs/talos_example-L1k_0NzX/lib/python3.6/site-packages/keras/engine/training.py", line 952, in fit
    batch_size=batch_size)
  File "/home/edgardm/.local/share/virtualenvs/talos_example-L1k_0NzX/lib/python3.6/site-packages/keras/engine/training.py", line 751, in _standardize_user_data
    exception_prefix='input')
  File "/home/edgardm/.local/share/virtualenvs/talos_example-L1k_0NzX/lib/python3.6/site-packages/keras/engine/training_utils.py", line 138, in standardize_input_data
    str(data_shape))
ValueError: Error when checking input: expected dense_1_input to have shape (8,) but got array with shape (4,)

Am I doing something wrong? I have some limited experience with ML, academic reading on hyperparameters optimization and no experience with Keras, but I was expecting this minimum example to work out-of-the box... =/

@mikkokotila
Copy link
Author

That's right, there was an error in the code. It's now fixed. Both the input and output dimensions were wrong.

@dileep3004
Copy link

Hi,

Small doubt You had initialized hidden_layers but didn't Used it.

Can you please Help me where to use it

@edmundackah
Copy link

@mikkokotila How do i use this with the keras image data generator?

@yonatanbitton
Copy link

Hey, what about the x_val, y_val here?

What happens if you don't pass x_val and y_val (Like in this example),

does it split it automatically?

Thanks

@blu3r4y
Copy link

blu3r4y commented Aug 17, 2019

I think the call ta.datasets.iris() changed to ta.templates.datasets.iris() and should be updated.

@ronammar
Copy link

Updated the script to work as of today. @mikkokotila, please pull or modify accordingly - thanks!
https://gist.github.com/ronammar/a62fe679ef156135faf5b171c39cd47e

@mikkokotila
Copy link
Author

mikkokotila commented Sep 25, 2019

What happens if you don't pass x_val and y_val (Like in this example)

You have to pass it.

How do i use this with the keras image data generator?

Have a look at the generator example in the docs.

@blu3r4y @ronammar @dileep3004 thanks for the corrections. It's now updated to the latest API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment