This repository contains an implementation of a Genetic model that tries to optimize the structure of a Convolution Neural Network (CNN).
only tensorflow
is needed. See requirements.txt and use pip install -r requirements.txt
for installation.
In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection. Some examples of GA applications include optimizing decision trees for better performance, solving sudoku puzzles, hyperparameter optimization, causal inference, etc. [Wiki].
-
📄 file [main.ipynb]
This file is my Demo file that shows how to use this classifier on
cifar10
dataset (provided bykeras.datasets
). -
📂 directory [genetic_cnn_optimizer]
-
📄 file [cnn_chromo.py]
This file contains
I have implemented two Crossover operations, the first one is a pivot-based crossover and the other uses a random binary list for dividing genomes. The mutation operation will change one genome randomly. There are three conditions that may happen in mutation. (a)change one genomeCNNChromo
class. This is the representation of a CNN in genetic. Each chromosome consists of an array:$L_{i}$ or$K_{i}$ (b)increase the number of layers (c)decrease the number of layers -
📄 file [genetic_cnn.py]
This file contains
GeneticCNN_finder
class. This is where Genetic Algorithm is implemented. The constructor of this class takes a parameteraccuracy_function
that should be a function for evaluating the accuracy of every CNN created by the genetic.
-