Creating a model - VasSkliris/mly GitHub Wiki
In this package you can also build simple Deep Neural Networks. Usually changing the parameters of a network can be a pain because you might forget changing one parameter and then you will have to run the network again. To simplify this procedure I simplified the building of such networks using the already simplified Keras functions.
The functions to use
To follow Keras documentation what we need is a model
object and to do that there are two main functions witch are in mly.models
directory.
conv_model_1D(parameter_matrix, INPUT_SHAPE, LR)
conv_model_2D(parameter_matrix, INPUT_SHAPE, LR)
Both of them are creating a convolutional neural network based on the parameter matrix, input shape and learning rate. The difference is that the first creates a network with one dimention as an input and the other one with two dimentional input. The main idea is to concentrate all the parameters you need for every layer in one column and create a matrix. Here is an example of input:
CORE = ['C','C','C','C','F','D','D','DR']
MAX_POOL = [ 2, 0, 0, 2, 0, 0, 0, 0 ]
FILTERS = [ 8, 16, 32, 64, 0, 64, 32, 0.3]
K_SIZE = [ 3, 3, 3, 3, 0, 0, 0, 0 ]
input_shape = (8192,3)
learning_rate = 0.0001
PM=[CORE,MAX_POOL,FILTERS,K_SIZE]
Core list has the type of the layer you want to add. Different types of layers can get different types of parameters. More specificaly:
- 'C' is for convolutional layer, it needs you to specify FILTERS (the depth of the output) and K_SIZE witch is the kernel size. You can also optionally specify MAX_POOL.
- 'D' is for dence (linear) layer. It needs to specify FILTERS only.
- 'F' is for flatten layer, witch just transforms the input into an one dimensional array.
- 'DR' is of dropout witch sets a random number of inputs into a near zero number. This helps with overfitting. The float percentage of dropout you want gets into the FILTERS array just for simplicity reasons.
So for example if you want to create the above 1 dimensional convolutional network you only need:
my_model = conv_model_1D(parameter_matrix = PM
, INPUT_SHAPE = input_shape
, LR = lr)
No you are ready to train the model. Although the format of the input data has to be very specific for consistency. For that reason mly has more simplifying function that are compatible with the generators of the data. To learn about them go to Feeding the model page.