jliphard / deepevolve Goto Github PK
View Code? Open in Web Editor NEWRapid hyperparameter discovery for neural nets using genetic algorithms
License: Other
Rapid hyperparameter discovery for neural nets using genetic algorithms
License: Other
I am getting the following error. Am I doing anything wrong?
$ git clone [email protected]:jliphard/DeepEvolve.git
$ git log -1 --pretty=format:"%H"
e9bf389a658aacf52a1bdacf4697ae4a704c0452
$ python3 brute.py
Using TensorFlow backend.
Traceback (most recent call last):
File "brute.py", line 98, in <module>
main()
File "brute.py", line 93, in main
genomes = generate_genome_list(all_possible_genes)
File "brute.py", line 75, in generate_genome_list
genome_obj.set_genes_to(genome, 0, 0)
File "/nevis/milne/files/gd2392/research/projects/DeepEvolve/genome.py", line 102, in set_genes_to
self.update_hash()
File "/nevis/milne/files/gd2392/research/projects/DeepEvolve/genome.py", line 43, in update_hash
+ str(self.geneparam['nb_layers']) + self.geneparam['optimizer']
File "/nevis/milne/files/gd2392/research/projects/DeepEvolve/genome.py", line 143, in nb_neurons
nb_neurons[i] = self.geneparam['nb_neurons_' + str(i+1)]
KeyError: 'nb_neurons_1'
I'm trying to run GA for mnist but getting Negative Dimension error randomly in different network combinations. Some models would compile fine and some would not.
Your code for compiling CNN model remains same as given below.
def compile_model_cnn(genome, nb_classes, input_shape):
"""Compile a sequential model.
Args:
genome (dict): the parameters of the genome
Returns:
a compiled network.
"""
# Get our network parameters.
nb_layers = genome.geneparam['nb_layers' ]
nb_neurons = genome.nb_neurons()
activation = genome.geneparam['activation']
optimizer = genome.geneparam['optimizer' ]
logging.info("Architecture:%s,%s,%s,%d" % (str(nb_neurons), activation, optimizer, nb_layers))
model = Sequential()
# Add each layer.
for i in range(0,nb_layers):
# Need input shape for first layer.
if i == 0:
model.add(Conv2D(nb_neurons[i], kernel_size = (3, 3), activation = activation, padding='same', input_shape = input_shape))
else:
model.add(Conv2D(nb_neurons[i], kernel_size = (3, 3), activation = activation))
if i < 2: #otherwise we hit zero
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.2))
model.add(Flatten())
# always use last nb_neurons value for dense layer
model.add(Dense(nb_neurons[len(nb_neurons) - 1], activation = activation))
model.add(Dropout(0.5))
model.add(Dense(nb_classes, activation = 'softmax'))
#BAYESIAN CONVOLUTIONAL NEURAL NETWORKS WITH BERNOULLI APPROXIMATE VARIATIONAL INFERENCE
#need to read this paper
model.compile(loss='categorical_crossentropy',
optimizer=optimizer,
metrics=['accuracy'])
return model
Below is the error report.
Getting Keras datasets
Compling Keras model
Architecture:[64, 16, 128, 16, 64, 128],relu,nadam,5
7%|โ | 1/15 [00:17<04:09, 17.81s/it]Traceback (most recent call last):
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/main.py", line 377, in <module>
main(dataset,nb_classes,batch_size,epochs,mode,population,generations,network,project_dir=project_dir)
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/main.py", line 339, in main
generate(evolution_params, dataset,nb_classes,batch_size,epochs,run,network,project_dir=project_dir)
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/main.py", line 232, in generate
train_genomes(genomes, dataset,i+1,run,nb_classes,batch_size,epochs,mode,network,project_dir=project_dir)
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/main.py", line 31, in train_genomes
genome.train(dataset,gen,run,nb_classes,batch_size,epochs,mode,network,project_dir=project_dir)
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/genome.py", line 123, in train
self.training_history,self.test_score,self.model_name = train_and_score(self, dataset,mode,gen,run,nb_classes,batch_size,epochs,network,project_dir=project_dir)
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/train.py", line 407, in train_and_score
model = compile_model_cnn(genome, nb_classes, input_shape,mode)
File "/home/shehzikhan/Projects/DeepWork/generaldeepevolution/train.py", line 259, in compile_model_cnn
model.add(Conv2D(nb_neurons[i], kernel_size = (3, 3), activation = activation))
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/keras/engine/sequential.py", line 185, in add
output_tensor = layer(self.outputs[0])
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/keras/engine/base_layer.py", line 457, in __call__
output = self.call(inputs, **kwargs)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/keras/layers/convolutional.py", line 168, in call
dilation_rate=self.dilation_rate)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 3565, in conv2d
data_format=tf_data_format)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 780, in convolution
return op(input, filter)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 868, in __call__
return self.conv_op(inp, filter)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 520, in __call__
return self.call(inp, filter)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.py", line 204, in __call__
name=self.name)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 956, in conv2d
data_format=data_format, dilations=dilations, name=name)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3155, in create_op
op_def=op_def)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1731, in __init__
control_input_ops)
File "/home/shehzikhan/pythonenvs/deepwork/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1579, in _create_c_op
raise ValueError(str(e))
ValueError: Negative dimension size caused by subtracting 3 from 2 for 'conv2d_5/convolution' (op: 'Conv2D') with input shapes: [?,2,2,16], [3,3,16,64].
Exception KeyError: KeyError(<weakref at 0x7f249b920e68; to 'tqdm' at 0x7f242b4391d0>,) in <object repr() failed> ignored
Hi,
i got the result like INFO - {'activation': 'relu', 'nb_layers': 2, 'optimizer': 'nadam', 'nb_neurons': [64, 64, 16, 16, 16, 128]}
Why the list of nb_neurons has six numbers (i mean, there is two nb_layers)?
Can it be modified to handle regression problems?
Hello, under what license is this project released under ? Thank-you.
Line 228 in train.py uses a fixed value rather than reading the length of the nb_neurons array.
Changing the line to the following may be helpful as a suggestion:
model.add(Dense(nb_neurons[len(nb_neurons) - 1], activation = activation))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.