maxpumperla / hyperas

Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization
http://maxpumperla.com/hyperas/
MIT License
2.18k stars 318 forks source link

data_args i optim.minimize #263

Closed croshong closed 4 years ago

croshong commented 4 years ago

Hi all

In FAQ it is written that

And when you run your trials, pass a tuple of arguments to be substituted in as data_args:

but When I tried to use in optim.minimize

There is an error like below TypeError: minimize() got an unexpected keyword argument 'data_args'

Attached files are entire code with hyperas

And Can I have any idea about how to pass argument in data() function?

Any kind of comment or suggestion would be appreciated

Thanks

hyperas_code.txt

hyperas_code.txt

JonnoFTW commented 4 years ago

Are you running the latest code from github? Run this to make sure you're running the latest code and try again:

pip uninstall hyperas
pip install -U git+https://github.com/maxpumperla/hyperas.git
croshong commented 4 years ago

Thanks Joanno

when I install hyperas again, the data_args seems to be recognized by hyperas.

But I have another stupid question. how to feed data argument into data_args?

In FAQ section, it is written that data argument should be fed using pickle format.

Can we use just simple string format?

JonnoFTW commented 4 years ago

@croshong you can use whatever you want, the pickle filename as a string is just an example. For my purposes, it was easier to pickle my data for distributed execution. You could conceivably have a url from where the data is fetched, or a number, or a list. Passing a complex object that cannot be reconstructed from repr will not work. What hyperas does is render a template file that is executed by hyperopt, if you set keep_temp=True you can check the generated file to see the result.

Suppose your data function is:

def data(a,b,c):
    ...

You can pass whatever you want in as long as it can be reproduced with repr like this:

arg_a = sys.argv[1]
arg_c = sys.argv[2]
for arg_b in [1,2,3]:
    optim.minimize(data_args=(arg_a, arg_b, arg_c),...)

Check the code in the commit to see what's going on when the template is generated:

https://github.com/maxpumperla/hyperas/commit/77c5d7c092fe9a43ead63964b110873ca6f11899#diff-5f4a71d5d8810661e56d870e213c5bbdR230-R236