Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run example code - TypeError('require string label') #106

Closed
bohoro opened this issue Jun 27, 2017 · 18 comments
Closed

Unable to run example code - TypeError('require string label') #106

bohoro opened this issue Jun 27, 2017 · 18 comments

Comments

@bohoro
Copy link

bohoro commented Jun 27, 2017

Hi,

I am unable to run the first hyperas example. Specifically this line:

>>> model.add(Dropout({{uniform(0, 1)}}))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/brohoro/Documents/PyProjects/envs/tensorflow/lib/python2.7/site-packages/hyperopt/pyll_utils.py", line 21, in wrapper
    raise TypeError('require string label')

The example without hyperas runs fine.

Here is my env

Python 2.7.13
Name: Keras
Version: 2.0.4
Name: hyperas
Version: 0.3
Name: hyperopt
Version: 0.1

I have tried this both via Jupyter and via the python interpreter.

Thanks

@maxpumperla
Copy link
Owner

Hi @bohoro, does it work if you install hyperas from master? It's been ages since I got around to release a new version.

@hi-ilkin
Copy link

There is also a problem with comments, try again after deleting comments in your code

@maxpumperla
Copy link
Owner

@huseynlilkin while this is absolutely true, I don't think it relates to this issue.

@nchuramani
Copy link

Hi @maxpumperla , I am facing the same problem with uniform and choice. I tried installing hyperas from master i.e. hyperas 0.4 but I am still facing the same issue.

@maxpumperla
Copy link
Owner

sorry to hear that. will look into the issue once back from vacation

@MMostavi
Copy link

Hi
I have the same issue with choice and uniform. Please if anyone has any suggestions, let me know!

@aydindemircioglu
Copy link

same for me, though i did not use the example but hacked it directly into my unet network.
btw, is it supported to have images as labels?

@rcox771
Copy link

rcox771 commented Jul 31, 2017

I had the same error earlier today, but mine was caused by not using double curly braces around my choices. Do you have a spot in your code where you're missing an extra set of braces?

before:
model.compile(loss='categorical_crossentropy', optimizer={choice(['rmsprop', 'adam', 'sgd'])}, metrics=['accuracy'])

after:
model.compile(loss='categorical_crossentropy', optimizer={{choice(['rmsprop', 'adam', 'sgd'])}}, metrics=['accuracy'])

@aydindemircioglu
Copy link

ok, at least in my case i realized that i call my network directly, did not see that (stupid me).
but i have still problems, a) i use python 2 and "from future import division", which needs to
be handled in extract_imports in utils.py like if 'print_function' in line or 'import division' in line:
b) i still get an error like

Traceback (most recent call last):
File "./hyperopt16bit.py", line 455, in
trials=Trials(15))
File "/usr/local/lib/python2.7/dist-packages/hyperas/optim.py", line 67, in minimize
verbose=verbose)
File "/usr/local/lib/python2.7/dist-packages/hyperas/optim.py", line 133, in base_minimizer
return_argmin=True),
File "/usr/local/lib/python2.7/dist-packages/hyperopt/fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "/usr/local/lib/python2.7/dist-packages/hyperopt/base.py", line 635, in fmin
return_argmin=return_argmin)
File "/usr/local/lib/python2.7/dist-packages/hyperopt/fmin.py", line 314, in fmin
pass_expr_memo_ctrl=pass_expr_memo_ctrl)
File "/usr/local/lib/python2.7/dist-packages/hyperopt/base.py", line 786, in init
pyll.toposort(self.expr)
File "/usr/local/lib/python2.7/dist-packages/hyperopt/pyll/base.py", line 715, in toposort
assert order[-1] == expr
IndexError: list index out of range

will see into it, what i am doing wrong.

@aydindemircioglu
Copy link

aydindemircioglu commented Aug 12, 2017

and the other thing is that my code was calling a function to create the model, like

def getUNet(): 
...

def trainStep():
    model = getUNet()

now the issue is fixed on my side.

@hacheemaster
Copy link

Any update on this issue? I'm still getting the 'require string label' error...

@nchuramani
Copy link

HI,
For me, only the uniform gives me the error now. I removed uniform and it worked. I have the updated versions of keras and hyperopt and the hyperas version from git master.

@shadiakiki1986
Copy link
Contributor

You can't execute the model creation code directly in python. You need to wrap your code in a def create_model(...): ... function, and then call it from optim.minimize(model=create_model,... like in the example in the readme.

My understanding is that the reason for this is that hyperas works is by doing template replacement of everything in the {{...}} into a separate temporary file, and then running the model with the replaced braces.

@kesarianubhav
Copy link

I have a function named model wherein I am creating layers,fitting to data . And i am calling that fnc from opt.minimize . But i am Still getting this error !! Any clues ??

@mbfair
Copy link

mbfair commented Jul 24, 2018

Hello, I realize this is an older thread, but I am getting the same issue as @aydindemircioglu:

assert order[-1] == expr
IndexError: list index out of range

Do you have insight on what caused / solved this issue? TIA

@jcatanza
Copy link

jcatanza commented Dec 8, 2020

Why is the issue closed?

It doesn't seem to be resolved. I (and others) still cannot run the example code without getting the 'TypeError: require string label' at the line

I have installed the latest versions of hyperopt and hyperas under python 3.6

model.add(Dropout({{uniform(0, 1)}}))

If the issue is resolved, can someone please describe how they are able to run this code without getting the TypError?

@shadiakiki1986
Copy link
Contributor

Where's your code?

@JonnoFTW
Copy link
Collaborator

JonnoFTW commented Dec 8, 2020

I ran the simple.py example just now and it worked fine for me.

Steps:

git clone https://github.com/maxpumperla/hyperas
cd hyperas
python3 -m venv ./venv
source venv/bin/activate
pip install -e .
pip install tensorflow
cd examples
# edit simple.py line 60 to epochs=1
python simple.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests