From 9be8896b22cbbaeaea265a42275c23c05d0c839c Mon Sep 17 00:00:00 2001 From: Francois Vieille Date: Mon, 11 Mar 2019 22:36:58 +0100 Subject: [PATCH] ajout d'un modele a convolution --- .gitignore | 3 +- iss/models/SimpleConvAutoEncoder.py | 48 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 iss/models/SimpleConvAutoEncoder.py diff --git a/.gitignore b/.gitignore index 3f853b5..da6bdc9 100644 --- a/.gitignore +++ b/.gitignore @@ -92,4 +92,5 @@ config/* !config/config.template.yaml # models dir -models/ \ No newline at end of file +models/ +!iss/models \ No newline at end of file diff --git a/iss/models/SimpleConvAutoEncoder.py b/iss/models/SimpleConvAutoEncoder.py new file mode 100644 index 0000000..a40d5ba --- /dev/null +++ b/iss/models/SimpleConvAutoEncoder.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +from iss.models.AbstractModel import AbstractModel +from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D, Reshape, Flatten +from keras.optimizers import Adadelta, Adam +from keras.models import Model +import numpy as np + +class SimpleConvAutoEncoder(AbstractModel): + + def __init__(self, config): + + save_directory = config['save_directory'] + model_name = config['model_name'] + + super().__init__(save_directory, model_name) + + self.activation = config['activation'] + self.input_shape = (config['input_height'], config['input_width'], config['input_channel']) + self.lr = config['learning_rate'] + self.build_model() + + def build_model(self): + input_shape = self.input_shape + + picture = Input(shape = input_shape) + + # encoded network + x = Conv2D(4, (3, 3), activation = 'relu', padding = 'same', name = 'enc_conv_1')(picture) + x = MaxPooling2D((2, 2))(x) + x = Conv2D(8, (3, 3), activation = 'relu', padding = 'same', name = 'enc_conv_2')(x) + encoded = MaxPooling2D((2, 2))(x) + + # decoded network + x = Conv2D(8, (3, 3), activation = 'relu', padding = 'same', name = 'dec_conv_1')(encoded) + x = UpSampling2D((2, 2))(x) + x = Conv2D(4, (3, 3), activation = 'relu', padding = 'same', name = 'dec_conv_2')(x) + x = UpSampling2D((2, 2))(x) + x = Flatten()(x) + x = Dense(np.prod(input_shape), activation = self.activation)(x) + decoded = Reshape((input_shape))(x) + + self.model = Model(picture, decoded) + + # optimizer = Adadelta(lr = self.lr, rho = 0.95, epsilon = None, decay = 0.0) + optimizer = Adam(lr = 0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False) + + self.model.compile(optimizer = optimizer, loss = 'binary_crossentropy')