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

Please help me with the error I'm getting #30

Closed
0xpranjal opened this issue Jul 6, 2021 · 3 comments
Closed

Please help me with the error I'm getting #30

0xpranjal opened this issue Jul 6, 2021 · 3 comments
Labels
question Further information is requested

Comments

@0xpranjal
Copy link

0xpranjal commented Jul 6, 2021

I am trying to run the following code :

import time
import numpy as np
from keras.datasets import cifar10
from tensorflow.keras.utils import to_categorical
from keras import optimizers

from hyperactive import RandomSearchOptimizer, ParticleSwarmOptimizer

(X_train, y_train), (X_test, y_test) = cifar10.load_data()

X_train = X_train.astype('float32')/255.0
X_test = X_test.astype('float32')/255.0

y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

sgd = optimizers.SGD(lr=0.01)
adam = optimizers.Adam(lr=0.01)

#this defines the structure of the model and print("time: {}".format(t2-t1))the search space in each layer
search_config = {
"keras.compile.0": {"loss": ["categorical_crossentropy"], "optimizer": [adam, sgd]},
"keras.fit.0": {"epochs": [10], "batch_size": range(10, 101), "verbose": [2]},
"keras.layers.Conv2D.1": {
"filters": range(4, 101),
"kernel_size": [3, 5, 7],
"activation": ["sigmoid", "relu", "tanh"],
"input_shape": [(32, 32, 3)],
},
"keras.layers.MaxPooling2D.2": {"pool_size": [(2, 2)]},
"keras.layers.Conv2D.3": {
"filters": range(4, 101),
"kernel_size": [3, 5, 7],
"activation": ["sigmoid", "relu", "tanh"],
},
"keras.layers.MaxPooling2D.4": {"pool_size": [(2, 2)]},
"keras.layers.Flatten.5": {},
"keras.layers.Dense.6": {"units": range(4, 201), "activation": ["sigmoid", "relu", "tanh"]},
"keras.layers.Dense.7": {"units": range(4, 201), "activation": ["sigmoid", "relu", "tanh"]},
#"keras.layers.Dropout.7": {"rate": list(np.arange(0.2, 0.8, 0.2))},
"keras.layers.Dense.8": {"units": [10], "activation": ["softmax"]},
}

Optimizer = ParticleSwarmOptimizer(search_config, n_iter=10, n_part=10, metric='accuracy', cv=0.8, w=0.7, c_k=2.0, c_s=2.0)
#Optimizer = ParticleSwarmOptimizer(search_config, n_iter=10, metric="accuracy", n_jobs=1, cv=3, verbosity=1, random_state=None, warm_start=False, memory=True, scatter_init=False, n_part=4, w=0.5, c_k=0.5, c_s=0.9)

t1 = time.time()
Optimizer.fit(X_train, y_train)
t2 = time.time()

print("time: {}".format(t2-t1))

Optimizer.predict(X_test)
score = Optimizer.score(X_test, y_test)

print("test score: {}".format(score))

But I am getting an issue,
Screenshot 2021-07-06 at 9 00 30 PM

@SimonBlanke SimonBlanke added the question Further information is requested label Jul 6, 2021
@SimonBlanke
Copy link
Owner

Hello @Bhard27,

the example you provided is from a ~2 year old API of Hyperactive (before version 1.0.0). The current version (which you probably have installed) is much easier to use.

Where did you get this example from?

If you are using the current version of Hyperactive you can take a look at the examples in the overview section of the readme. In there is an example for the Keras package.

@0xpranjal
Copy link
Author

0xpranjal commented Jul 6, 2021

Thanks for the reply back.

Sorry, yes you're right. Your package was mentioned and stored locally in an old project I was trying to implement. Link.

Thanks for sharing the Keras example with me, that is really helpful. I'm able to run the tests by using a custom optimizer.

@SimonBlanke
Copy link
Owner

Very interesting: The old project is from "TatsukiSerizawa". I recognize him as one of the first users of Hyperactive.

If you are new to Hyperactive you should check out the Hyperactive Tutorial Notebook. It explains the most important features of Hyperactive and has a lot of visualizations.

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

No branches or pull requests

2 participants