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 error in your "complete example" #54

Closed
ghost opened this issue Dec 5, 2016 · 4 comments
Closed

Comments

@ghost
Copy link

ghost commented Dec 5, 2016

@maxpumperla Hi Max,
I think there is a serious issue whenever we utilize loops in hyperas. for example in your complete example in the first page of your GitHub repo, I get the following error:

File "", line 39
if conditional({{choice(['three', 'four'])}}) == 'four':
^
IndentationError: unexpected indent

I put the very complete/modified example of your code here:
`
from hyperopt import Trials, STATUS_OK, tpe
from hyperas import optim
from hyperas.distributions import choice, uniform, conditional
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.normalization import BatchNormalization
from keras.layers.advanced_activations import LeakyReLU, SReLU, PReLU, ThresholdedReLU

def data():
"""
Data providing function:

This function is separated from model() so that hyperopt
won't reload data for each evaluation run.
"""
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape(60000, 784)
X_test = X_test.reshape(10000, 784)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
nb_classes = 10
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_test = np_utils.to_categorical(y_test, nb_classes)
return X_train, Y_train, X_test, Y_test

def model(X_train, Y_train, X_test, Y_test):
"""
Model providing function:

Create Keras model with double curly brackets dropped-in as needed.
Return value has to be a valid python dictionary with two customary keys:
    - loss: Specify a numeric evaluation metric to be minimized
    - status: Just use STATUS_OK and see hyperopt documentation if not feasible
The last one is optional, though recommended, namely:
    - model: specify the model just created so that we can later use it again.
"""
model = Sequential()
model.add(Dense(512, input_shape=(784,)))
model.add(BatchNormalization())
model.add(Activation({{choice(['relu', 'softplus', 'softsign'])}}))
model.add(Dropout({{uniform(0, 0.5)}}))

model.add(Dense({{choice([32, 64, 128, 256, 512, 768, 1024])}}))
model.add(BatchNormalization())
model.add(Activation({{choice(['relu', 'sigmoid', 'hard_sigmoid', 'softmax', 'tanh', 'softplus', 'softsign'])}}))
model.add(Dropout({{uniform(0, 0.5)}}))

# If we choose 'four', add an additional fourth layer
# if conditional({{choice(['three', 'four'])}}) == 'four':
for _ in range(1, conditional({{choice([1, 4, 8, 16])}})):
    # model.add(Dense(100))
    model.add(Dense({{choice([32, 64, 128, 256, 512, 768, 1024])}}))
    model.add(BatchNormalization())
    # We can also choose between complete sets of layers
    model.add({{choice([Dropout(0.5), Dropout(0.25),
                        Activation('linear'), Activation('relu'), Activation('hard_sigmoid'), Activation('softmax')])}})
    model.add(Activation('relu'))

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

model.compile(loss='categorical_crossentropy', metrics=['accuracy'],
              optimizer={{choice(['rmsprop', 'adam', 'sgd', 'nadam', 'adadelta', 'adamax', 'adagrad'])}})

model.fit(X_train, Y_train,
          batch_size={{choice([64, 128, 256, 512, 768, 1024])}},
          nb_epoch=1,
          verbose=2,
          validation_data=(X_test, Y_test))
score, acc = model.evaluate(X_test, Y_test, verbose=0)
print('Test accuracy:', acc)
return {'loss': -acc, 'status': STATUS_OK, 'model': model}

best_run, best_model = optim.minimize(model=model,
data=data,
algo=tpe.suggest,
max_evals=100,
trials=Trials(), notebook_name="simple_notebook")
best_model.save("best_model.h5")
X_train, Y_train, X_test, Y_test = data()
print("Evaluation of best performing model:")
print(best_model.evaluate(X_test, Y_test))
print(best_model.summary())
`

If you run this code, you will get.

File "", line 57
for _ in range(1, conditional({{choice([1, 4, 8, 16])}})):
^
IndentationError: unexpected indent

so, it is serious issue, and I think it's because you might forget special note there... the code work properly in previous versions :(

@ghost ghost changed the title IndentationError: unexpected indent in your "complete example" IndentationError: unexpected indent error in your "complete example" Dec 5, 2016
@maxpumperla
Copy link
Owner

Yes, that's very unfortunate. Thanks for reporting this. I'll investigate and add this case to the unit tests.

@ghost
Copy link
Author

ghost commented Dec 5, 2016

@maxpumperla I think it is hopefully not a big deal as it worked properly in previous version...
Also, I put the very complete example of hyperas which can be added to hyperas example directory if you are interested in...

@maxpumperla
Copy link
Owner

@ErmiaAzarkhalili fixed on master, was a very silly mistake

@ghost
Copy link
Author

ghost commented Dec 5, 2016

@maxpumperla Thanks, So we can close this issue...(I will open new issue for advanced layers in next days...)

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

1 participant