I came to know scikit-optimize
package , and I am relatively new to Bayesian optimization which I want to use it in my current Convolutional NN. However, I tried to find best hyperparameters of convolutional NN by using Bayesian-optimization
but my current attempt is not working properly.
So far, I tried to come up implementation for this purpose but my code is not working properly which I don't know which part of my code remain issues. Can anyone point me out how to make this right? Is there any efficient implementation for using Bayesian optimization on convolutional NN for the sake of finding best hyperparameters? Any possible thoughts?
update
I tried GridSearchCV
, RandomSearchCV
for my convolutional NN which has really deep layer, and using GridSearchCV
took too much time to complete even 2-3 whole days can't finish the optimization. I want to use new optimization framework like bayesian-optimization (i.e, skopt
, optuna
) for finding best param and hyperparams of convolutional NN. Can anyone provide possible remedy and efficient approach to my current attempt 1 in colab and my attempt 2 in colab ? Any thoughts?
my current attempt:
here is my current attempt where I used scikit-optimize
package for Bayesian optimization. here is my attempt in this colab where I ran all my experiment of implementing Bayesian optimization on convolutional NN to find its best hyperparams:
### function returned to Bayesian Optimization
@use_named_args(dimensions=dimensions)
def bayes_opt(cnn_num_steps, cnn_init_epoch, cnn_max_epoch,
cnn_learning_rate_decay, cnn_batch_size, cnn_dropout_rate, cnn_init_learning_rate):
global iteration, num_steps, init_epoch, max_epoch, learning_rate_decay, dropout_rate, init_learning_rate, batch_size
num_steps = np.int32(cnn_num_steps)
batch_size = np.int32(cnn_batch_size)
learning_rate_decay = np.float32(cnn_learning_rate_decay)
init_epoch = np.int32(cnn_init_epoch)
max_epoch = np.int32(cnn_max_epoch)
dropout_rate = np.float32(cnn_dropout_rate)
init_learning_rate = np.float32(cnn_init_learning_rate)
tf.reset_default_graph()
tf.set_random_seed(randomState)
sess = tf.Session()
(train_X, train_y), (test_X, test_y) = cifar10.load_data()
train_X = train_X.astype('float32') / 255.0
test_X = test_X.astype('float32') / 255.0
targets = tf.placeholder(tf.float32, [None, input_size], name="targets")
model_learning_rate = tf.placeholder(tf.float32, None, name="learning_rate")
model_dropout_rate = tf.placeholder_with_default(0.0, shape=())
global_step = tf.Variable(0, trainable=False)
prediction = cnn(model_dropout_rate, model_learning_rate)
model_learning_rate = tf.train.exponential_decay(learning_rate=model_learning_rate, global_step=global_step, decay_rate=learning_rate_decay,
decay_steps=init_epoch, staircase=False)
with tf.name_scope('loss'):
model_loss = tf.losses.mean_squared_error(targets, prediction)
with tf.name_scope('adam_optimizer'):
train_step = tf.train.AdamOptimizer(model_learning_rate).minimize(model_loss,global_step=global_step)
sess.run(tf.global_variables_initializer())
for epoch_step in range(max_epoch):
for batch_X, batch_y in generate_batches(train_X, train_y, batch_size):
train_data_feed = {
inputs: batch_X,
targets: batch_y,
model_learning_rate: init_learning_rate,
model_dropout_rate: dropout_rate
}
sess.run(train_step, train_data_feed)
## how to return validation error, any idea?
## return validation error
## return val_error
my current attempt in colab is still have various issues and it hasn't done yet. Can anyone provide possible workable approach by using bayesian optimization for finding best hyperparams of very deep convolutional NN? Any thoughts? Thanks!