maxpumperla / hyperas

Keras + Hyperopt: A very simple wrapper for convenient hyperparameter optimization

Home Page:http://maxpumperla.com/hyperas/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: 'generator' object is not subscriptable

brunoklein99 opened this issue · comments

from hyperas import optim
from hyperopt import Trials, tpe


def data():
    return 1, 2, 3, 4


def model(a, b, c, d):
    pass


if __name__ == "__main__":

    trials = Trials()
    bla = optim.minimize(model=model, data=data, algo=tpe.suggest,
                         max_evals=5,
                         trials=trials)

C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\python.exe G:/Source/untitled4/main.py
Using TensorFlow backend.
Traceback (most recent call last):
>>> Imports:
  File "G:/Source/untitled4/main.py", line 18, in <module>
#coding=utf-8
    trials=trials)

try:
    from hyperas import optim
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperas\optim.py", line 67, in minimize
except:
    pass
    verbose=verbose)

  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperas\optim.py", line 133, in base_minimizer
try:
    return_argmin=True),
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\fmin.py", line 307, in fmin
    from hyperopt import Trials, tpe
    return_argmin=return_argmin,
except:
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\base.py", line 635, in fmin
    pass

    return_argmin=return_argmin)
>>> Hyperas search space:

def get_space():
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\fmin.py", line 314, in fmin
    return {
    }
    pass_expr_memo_ctrl=pass_expr_memo_ctrl)

  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\base.py", line 786, in __init__
>>> Data
    pyll.toposort(self.expr)
1: 
2: 
  File "C:\Users\klein-desk\AppData\Local\Programs\Python\Python35\lib\site-packages\hyperopt\pyll\base.py", line 715, in toposort
3: 
4: 
    assert order[-1] == expr
>>> Resulting replaced keras model:
TypeError: 'generator' object is not subscriptable

 1: def keras_fmin_fnct(space):
 2: 
 3:     pass
 4: 

Process finished with exit code 1

Windows
Python 3.5.2

try
pip3 install networkx==1.11

I would only do this in virtual env as the current networkx version is 2.0

Doc here:
https://networkx.github.io/

Hi @maxpumperla
As you might know, it's the temporary solution. Do you have any idea to update Hyperopt to be compatible with this version of netwrokx? As I know you have the full access to modify the hyperopt repo. :)

Not only is this a temporary solution, but it also happens to be one that only works on Python 2.x. The set-up script for networkx 1.1 has a print statement!

(tensorflow) Epictetus:notebooks artem$ pip3 install networkx==1.1
Collecting networkx==1.1
  Downloading networkx-1.1.zip (813kB)
    100% |████████████████████████████████| 819kB 982kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/38/w_gkw9l57ysgm1whbwngyf3w0000gn/T/pip-build-84uqyau_/networkx/setup.py", line 18
        print "To install, run 'python setup.py install'"
\

Networkx 2.0 uses generators instead of lists.
Just change line 714 in pyll/base.py to:
order = list(nx.topological_sort(G))

@jhmenke
Thanks for the hint, but it results in the following error afterwards:

File "\hyperopt\pyll\base.py", line 320, in arg
fn = scope._impls[self.name]

KeyError: 'hyperopt_param'

Any ideas how to solve it?.. Thanks!
EDIT: btw, even with networkx==1.11 the sample code doesn't work, I just get another error message (this time from networkx).

that's an unrelated issue then. you should open a new issue with reproduceable code so people can help.