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

IndentationError: unexpected indent #67

Closed
ThomasAger opened this issue Jan 28, 2017 · 16 comments
Closed

IndentationError: unexpected indent #67

ThomasAger opened this issue Jan 28, 2017 · 16 comments

Comments

@ThomasAger
Copy link

Hey, I just installed on python 3.4.2 and I'm using the PyCharm IDE. I've opened the example file in my ide and attempted to run it. The following error occurs:

Using Theano backend.
Traceback (most recent call last):
  File "D:/Dropbox/Dropbox/PhD/My Work/Code/Paper 2/src/temp.py", line 77, in <module>
    trials=Trials())
  File "C:\Anaconda3\envs\py34\lib\site-packages\hyperas\optim.py", line 42, in minimize
    notebook_name=notebook_name, verbose=verbose)
  File "C:\Anaconda3\envs\py34\lib\site-packages\hyperas\optim.py", line 62, in base_minimizer
    model_str = get_hyperopt_model_string(model, data, notebook_name, verbose, stack)
  File "C:\Anaconda3\envs\py34\lib\site-packages\hyperas\optim.py", line 132, in get_hyperopt_model_string
    imports = extract_imports(cleaned_source, verbose)
  File "C:\Anaconda3\envs\py34\lib\site-packages\hyperas\utils.py", line 31, in extract_imports
    tree = ast.parse(source)
  File "C:\Anaconda3\envs\py34\lib\ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 35
    if conditional({{choice(['three', 'four'])}}) == 'four':
    ^
IndentationError: unexpected indent

I understand that this may be because there is a mixing of tabs and spaces? I will be attempting to resolve it under that understanding next and update here if that is the case.

@ThomasAger
Copy link
Author

I tried replacing the tabs with spaces in my own example file and it didn't work.

@tfriedel
Copy link

I have the same problem with python 2.7.

@tfriedel
Copy link

tfriedel commented Jan 31, 2017

Seems to be a bug with the function that strips the source of comments remove_all_comments.
This is part of the input source:
`
model.add(Dropout({{uniform(0, 1)}}))

# If we choose 'four', add an additional fourth layer
if conditional({{choice(['three', 'four'])}}) == 'four':
    model.add(Dense(100))
    # We can also choose between complete sets of layers
    model.add({{choice([Dropout(0.5), Activation('linear')])}})
    model.add(Activation('relu'))

model.add(Dense(10))
model.add(Activation('softmax'))

`

And this is the output:
`
model.add(Dropout({{uniform(0, 1)}}))

    if conditional({{choice(['three', 'four'])}}) == 'four':
    model.add(Dense(100))
            model.add({{choice([Dropout(0.5), Activation('linear')])}})
    model.add(Activation('relu'))

model.add(Dense(10))
model.add(Activation('softmax'))

`

@peroon
Copy link

peroon commented Feb 13, 2017

I commented out and worked.

    """
    # If we choose 'four', add an additional fourth layer
    if conditional({{choice(['three', 'four'])}}) == 'four':
        model.add(Dense(100))
        # We can also choose between complete sets of layers
        model.add({{choice([Dropout(0.5), Activation('linear')])}})
        model.add(Activation('relu'))
    """

@justiceamoh
Copy link

I am having the same issues and commenting out isn't helping. I also see it with the data function:

def data():
    (X_train, y_train), (X_test, y_test) = mnist.load_data()
    nb_class = 10

    # Reshape X data from 2D to 1D (28x28 to 784)
    X_train = X_train.reshape(60000,784).astype('float32')
    X_test  = X_test.reshape(10000,784).astype('float32')

    X_train /= 255
    X_test /= 255    

    # Convert Y labels to Categorical One-Hot Format
    y_train = np_utils.to_categorical(y_train, nb_class)
    y_test = np_utils.to_categorical(y_test, nb_class)

    return X_train, y_train, X_test, y_test

And the error code is:

 File "<unknown>", line 29
    X_train = X_train.reshape(60000,784).astype('float32')
    ^
IndentationError: unexpected indent

I saw #54 but it's not clear from there how to rectify the issue.

@justiceamoh
Copy link

Actually, I realize this bug has been fixed in master. So don't use the standard pip version, install directly from master to rectify the issue.

@tfriedel
Copy link

If you remove all comments ( # .... ) from your code, it will work. Of course this is only a short term workaround and I hope remove_all_comments will get fixed properly.

@abourai
Copy link

abourai commented Feb 17, 2017

Any chance this change can get added to pip as well soon?

@mpariente
Copy link

So is this version not uo to date? https://pypi.python.org/pypi/hyperas/0.3

Sorry for the dummy question but how can I install directly from master ?
Thanks in advance

@justiceamoh
Copy link

Yes, the pip version is not up to date. And, there's no such things as a dummy question :)

pip install git+https://github.com/maxpumperla/hyperas.git@master

@mpariente
Copy link

Thanks a lot !
Weirdly enough, it says requirement already satisfied for all packages..

@SergioChevtchenko
Copy link

I used --upgrade option to update my previously installed version from pip. Otherwise it says requirement already satisfied for all packages.

pip install git+https://github.com/maxpumperla/hyperas.git@master --upgrade

maxpumperla added a commit that referenced this issue Mar 29, 2017
Updated readme examples for keras 2.0, solving #67 #56
@maxpumperla
Copy link
Owner

above PR was just merged and shows an example of how to run an example without any of the issues.

@maxpumperla
Copy link
Owner

I think this is resolved, please re-open in case I'm wrong! thanks

@Leonardojessica
Copy link

Ola amigos estou com mesmo problema sera que podiam me ajudar

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
print('Digo algo!')
audio = r.listem(source)

try:
print('você disse: ' + r.recognizer_google(audio, language= "pt-br"))
except sr.UnknowValueError:
print("Ana não pode entender o audio")
except sr.RequestError as e:
print("Erro ao chamar google speech recognition service; {e}".format(e))

@porterchild
Copy link

porterchild commented Jan 29, 2019

I had the same issue, I solved it by changing my tab-indented file to a 4 space-indented file.

Took awhile to debug, seems like this could still use some work.

Repository owner locked and limited conversation to collaborators Jan 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants