Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions app/cnn/MkCCNApp.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//************************************************************************************************//
// //
// Code part of the project MLKL //
// //
// couet.julien@gmail.com //
// //
//************************************************************************************************//

require MLKL;


operator entry() {

String path_config = "C:/Users/Julien/Documents/Dev/MLKL/app/cnn/cnn_config.mlkl";
String path_image = 'C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/4.bmp';

// Load the configuration file and set the network layers
MkCNNConfig config;
MkCNNLayer layers[];
if(!config.config(path_config, layers))
return;

// Create the network
MkCNNNetwork nn(config, layers);

// Set the initiale learning rate
nn.optimizer().learningRate(nn.optimizer().learningRate()* sqrt(config.batch_size));
nn.display();

// Declare the enumeration, here we can set the larning rate decay
// However, it should be set from the file, see Convnet for this
MkCNNEnumEpoch epoch_enum();

// Load the training data
MkCNNData data = LoadTrainingCIFAR(config, true, -1.0, -1.0);
//data.loadTrainingMNIST(config);

// Train the network
// The network (the layers' weights) is tested and saved at each epch
nn.train(config, data, epoch_enum);


// Finally test it and save it
Float64 image_data[][] = LoadValidationCIFAR(config, true, -1.0, -1.0);
report(nn.predictRescale(image_data));
}

65 changes: 65 additions & 0 deletions app/cnn/cnn_config.mlkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### MLKL network configuration


##############################################################################
#
# 1. Network parameters
# tool* : "train" or "predict"
# gpu : GPU (0, 1)
# nbEpoch : Number of epochs
# batchSize : Batch size
# optimizer : Optimisation (0 : GD, 1 : GDLM)
# lossFunction : Loss funtion (0 : MSE, 1 : CE)
#
# 2. Layer definitions
# layersDefsPath : Path to the layers definition file
# layersParamsPath : Path to the layers parameters file
#
# 3. Images and labels
# trainImagesPath : Path of the train images, use for training
# trainLabelsPath : Path of the train labels, use for training
# testImagesPath* : Path of the test images, use for training
# testLabelsPath* : Path of the test labels, use for training
#
# 4. Network saving and loading
# save : Save the netwok
# autoSaving* : Automatically save the network at each epoch (0, 1)
# saveDirPath : Path of the network output folder
# saveFileName* : Name of the network output file
# loadFilePath* : Path of the network file to load
#
##############################################################################


# 1. Network parameters
tool=train
gpu=0
nbEpoch=5
batchSize=10
optimizer=3
lossFunction=0


# 2. Layer definitions
layersDefsPath=C:/Users/Julien/Documents/Dev/MLKL/app/cnn/cnn_layers_def.mlkl
layersParamsPath=C:/Users/Julien/Documents/Dev/MLKL/app/cnn/cnn_layers_params.mlkl


# 3. Images and labels
# For CIFAR, the same file contains both the image and labels
trainImagesPath=C:/Users/Julien/Documents/Dev/MLKL/resources/cifar-10/data_batch_1.bin
testImagesPath=C:/Users/Julien/Documents/Dev/MLKL/resources/cifar-10/test_batch.bin

# For MNIST
#trainImagesPath=C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/train-images.idx3-ubyte
#testImagesPath=C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/t10k-images.idx3-ubyte
#trainLabelsPath=C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/train-labels.idx1-ubyte
#testLabelsPath=C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/t10k-labels.idx1-ubyte


# 4. Network saving and loading
save=1
autoSaving=1
saveDirPath=C:/Users/Julien/Documents/Dev/MLKL/resources/
saveFileName=cnn_network.mlkl
#loadFilePath=C:/Users/Julien/Documents/Dev/MLKL/resources/2015-07-04_18-25-59/res.mlkl
75 changes: 75 additions & 0 deletions app/cnn/cnn_layers_def.mlkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
### MLKL layers definition


##############################################################################
#
# [name] : Name of the layer
# type : Type (data, conv, pool, fc)
# neuron : Neuron (tanh, relu, sigm, id)
# filters : number of filters
# filterSize : Filter size
# inChannels : Number of channels inputs
# outChannels : Number of channels outputs
# initW : Initiliaze the weights with a normal dist of mean initW
# initB : Add bias initB
#
##############################################################################

[conv1]
type=conv
neuron=relu
filters=32
filterSize=5
inChannels=3
outChannels=6
#initW=0.0
#initB=0.0

[pool1]
type=pool
pool=avg
neuron=relu
filters=28
inChannels=6
poolingSize=2
#initW=0.0
#initB=0.0

[conv2]
type=conv
neuron=relu
filters=14
filterSize=5
inChannels=6
outChannels=16
#initW=0.0
#initB=0.0

[pool2]
type=pool
pool=avg
neuron=relu
filters=10
inChannels=16
poolingSize=2
#initW=0.0
#initB=0.0

[conv3]
type=conv
neuron=relu
filters=5
filterSize=5
inChannels=16
outChannels=120
#initW=0.0
#initB=0.0

[fc3]
type=fc
neuron=relu
inChannels=120
outChannels=10
#initW=0.0
#initB=0.0

75 changes: 75 additions & 0 deletions app/cnn/cnn_layers_def_64.mlkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
### MLKL layers definition


##############################################################################
#
# [name] : Name of the layer
# type : Type (data, conv, pool, fc)
# neuron : Neuron (tanh, relu, sigm, id)
# filters : number of filters
# filterSize : Filter size
# inChannels : Number of channels inputs
# outChannels : Number of channels outputs
# initW : Initiliaze the weights with a normal dist of mean initW
# initB : Add bias initB
#
##############################################################################

[conv1]
type=conv
neuron=relu
filters=64
filterSize=5
inChannels=3
outChannels=6
#initW=0.0
#initB=0.0

[pool1]
type=pool
pool=avg
neuron=relu
filters=60
inChannels=6
poolingSize=2
#initW=0.0
#initB=0.0

[conv2]
type=conv
neuron=relu
filters=30
filterSize=5
inChannels=6
outChannels=16
#initW=0.0
#initB=0.0

[pool2]
type=pool
pool=avg
neuron=relu
filters=26
inChannels=16
poolingSize=2
#initW=0.0
#initB=0.0

[conv3]
type=conv
neuron=relu
filters=13
filterSize=5
inChannels=16
outChannels=120
#initW=0.0
#initB=0.0

[fc3]
type=fc
neuron=relu
inChannels=9720
outChannels=10
#initW=0.0
#initB=0.0

41 changes: 41 additions & 0 deletions app/cnn/cnn_layers_params.mlkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
### MLKL layers parameters


##############################################################################
#
# [name] : Name of the layer
# epsW : Type (data, conv, pool, fc)
# epsB : Neuron (relu, relu, exp)
# momW :
# momB : Windowing size
# wc : Number of inputs
#
##############################################################################

[conv1]
epsW=1
epsB=1
momW=1
momB=1
wc=1

[conv2]
epsW=2
epsB=2
momW=2
momB=2
wc=2

[conv3]
epsW=3
epsB=3
momW=3
momB=3
wc=3

[fc3]
epsW=4
epsB=4
momW=4
momB=4
wc=4
59 changes: 59 additions & 0 deletions app/cnn/sample/MkCCNSample_DAE.kl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//************************************************************************************************//
// //
// Code part of the project MLKL //
// //
// couet.julien@gmail.com //
// //
//************************************************************************************************//

require MLKL;

function MkCNNConfig ConfigMLP() {
MkCNNConfig config;

config.save=0;
config.gpu=0;
config.epoch = 20;
config.batch_size = 10;
config.optimizer = MK_OPTIMIZER_GD;
config.loss_function = MK_LOSS_MSE;

config.train_images_path = "C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/train-images.idx3-ubyte";
config.test_images_path = "C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/t10k-images.idx3-ubyte";
config.train_labels_path = "C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/train-labels.idx1-ubyte";
config.test_labels_path = "C:/Users/Julien/Documents/Dev/MLKL/resources/mnist/t10k-labels.idx1-ubyte";

return config;
}

function MkCNNLayer[] ConstructMLP(
Index nb_input_units,
Index nb_hidden_units,
Index nb_output_units)
{
MkCNNLayer layers[];
//layers.push(MkCNNLayerConvolutional(MK_NEURON_TANH, 32, 5, 5, 16, 120));
layers.push(MkCNNLayerFully(MK_NEURON_TANH, nb_input_units, nb_hidden_units));
layers.push(MkCNNLayerFully(MK_NEURON_TANH, nb_hidden_units, nb_output_units));
return layers;
}

operator entry() {

Index nb_hidden_neuron = 200;
MkCNNConfig config = ConfigMLP();
MkCNNLayer layers[] = ConstructMLP(32*32, nb_hidden_neuron, 10);
MkCNNNetwork nn(config.loss_function, config.optimizer, layers);

nn.display();
// load MNIST dataset
MkCNNData data;
data.loadTrainingMNIST(config);

nn.optimizer().learningRate(0.001);

// Declare the enumeration, here we can set the larning rate decay
MkCNNEnumEpoch epoch_enum();

nn.train(data, config, epoch_enum);
}
Loading