def build_model(encoder_dim=50, bottleneck_dim=20): encoder = Dense(encoder_dim, input_dim=28 * 28, activation='tanh') bottleneck = Dense(bottleneck_dim, activation='tanh') bottleneck_2 = DependentDense(encoder_dim, bottleneck, activation='tanh') decoder = DependentDense(28 * 28, encoder, activation='tanh') model = models.Sequential() model.add(encoder) model.add(bottleneck) model.add(bottleneck_2) model.add(decoder) return model, encoder
def build_model(nb_filters=32, nb_pool=2, nb_conv=3): model = models.Sequential() d = Dense(30) c = Convolution2D(nb_filters, nb_conv, nb_conv, border_mode='same', input_shape=(1, 28, 28)) # ========= ENCODER ======================== model.add(c) model.add(Activation('tanh')) model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool))) model.add(Dropout(0.25)) # ========= BOTTLENECK ====================== model.add(Flatten()) model.add(d) model.add(Activation('tanh')) # ========= BOTTLENECK^-1 ===================== model.add(DependentDense(nb_filters * 14 * 14, d)) model.add(Activation('tanh')) model.add(Reshape((nb_filters, 14, 14))) # ========= DECODER ========================= model.add(UpSampling2D(size=(nb_pool, nb_pool))) model.add(Deconvolution2D(c, border_mode='same')) model.add(Activation('tanh')) return model
def build_model(nb_filters=32, nb_pool=2, nb_conv=2): model = models.Sequential() d = Dense(60) c = Convolution2D(nb_filters, nb_conv, nb_conv, border_mode='same', input_shape=(28, 28, 1)) mp = MaxPooling2D(pool_size=(nb_pool, nb_pool)) # ========= ENCODER ======================== model.add(c) model.add(Activation('relu')) model.add(mp) model.add(Dropout(0.25)) # ========= BOTTLENECK ====================== model.add(Flatten()) model.add(d) model.add(Activation('relu')) # ========= BOTTLENECK^-1 ===================== model.add(DependentDense(units=nb_filters * 14 * 14, master_layer=d)) model.add(Activation('relu')) model.add(Reshape((nb_filters, 14, 14))) # ========= DECODER ========================= model.add(DePool2D(mp, size=(nb_pool, nb_pool))) model.add( Deconvolution2D(binded_conv_layer=c, border_mode='same', filters=nb_filters, kernel_size=(nb_conv, nb_conv))) model.add(Activation('relu')) return model
def get_decoder(C_1, C_2, C_3, c, c2, d, mp, mp2, nb_pool): decoder = models.Sequential() decoder.add( DependentDense(d.input_shape[1], d, input_shape=(d.output_shape[1], ))) decoder.add(Activation('tanh')) decoder.add(Reshape((C_2, 8, 8))) # ==================================================== # decoder.add(DePool2D(mp3, size=(nb_pool, nb_pool))) # decoder.add(Deconvolution2D(c3, nb_out_channels=C_2, border_mode='same')) # decoder.add(Activation('tanh')) # ==================================================== decoder.add(DePool2D(mp2, size=(nb_pool, nb_pool))) decoder.add(Deconvolution2D(c2, nb_out_channels=C_1, border_mode='same')) decoder.add(Activation('tanh')) # ==================================================== decoder.add(DePool2D(mp, size=(nb_pool, nb_pool))) decoder.add(Deconvolution2D(c, nb_out_channels=3, border_mode='same')) decoder.add(Activation('tanh')) # ==================================================== return decoder
def build_model(nb_filters=32, nb_pool=2, nb_conv=3): model = models.Sequential() d = Dense(30) c = Convolution2D(nb_filters, (nb_conv, nb_conv), padding='same', input_shape=(28, 28, 1)) mp =MaxPooling2D(pool_size=(nb_pool, nb_pool), padding='same') # ========= ENCODER ======================== model.add(c) model.add(Activation('tanh')) model.add(mp) model.add(Dropout(0.25)) # ========= BOTTLENECK ====================== model.add(Flatten()) model.add(d) model.add(Activation('tanh')) # ========= BOTTLENECK^-1 ===================== model.add(DependentDense(nb_filters * 14 * 14, d)) model.add(Activation('tanh')) model.add(Reshape((14, 14, nb_filters))) # ========= DECODER ========================= model.add(DePool2D(mp, size=(nb_pool, nb_pool))) model.add(Conv2DTranspose(1, (nb_conv, nb_conv), padding='same')) model.add(Activation('tanh')) return model
def build_model(nb_filters=32, nb_pool=2, nb_conv=3): C_1 = 64 C_2 = 32 C_3 = 16 c1 = Convolution2D(C_1, nb_conv, nb_conv, border_mode='same', name='c1', input_shape=(3, 32, 32)) mp1 = MaxPooling2D(pool_size=(nb_pool, nb_pool), name='mp1') c2 = Convolution2D(C_2, nb_conv, nb_conv, border_mode='same', name='c2') mp2 = MaxPooling2D(pool_size=(nb_pool, nb_pool), name='mp2') c3 = Convolution2D(C_3, nb_conv, nb_conv, border_mode='same', name='c3') mp3 = MaxPooling2D(pool_size=(nb_pool, nb_pool), name='mp3') d = Dense(100, name='encoded') model = Sequential() # ==================================================== model.add(c1) model.add(Activation('tanh')) model.add(mp1) # ==================================================== model.add(Dropout(0.25)) # ==================================================== model.add(c2) model.add(Activation('tanh')) model.add(mp2) # ==================================================== model.add(c3) model.add(Activation('tanh')) model.add(mp3) # ==================================================== model.add(Dropout(0.25)) # ==================================================== model.add(Flatten()) model.add(d) model.add(Activation('tanh')) # ==================================================== model.add( DependentDense(d.input_shape[1], d, input_shape=(d.output_shape[1], ))) model.add(Activation('tanh')) model.add(Reshape((C_3, 4, 4))) # ==================================================== model.add(DePool2D(mp3, size=(nb_pool, nb_pool))) model.add(Deconvolution2D(c3, nb_out_channels=C_2, border_mode='same')) model.add(Activation('tanh')) # ==================================================== model.add(DePool2D(mp2, size=(nb_pool, nb_pool))) model.add(Deconvolution2D(c2, nb_out_channels=C_1, border_mode='same')) model.add(Activation('tanh')) # ==================================================== model.add(DePool2D(mp1, size=(nb_pool, nb_pool))) model.add(Deconvolution2D(c1, nb_out_channels=3, border_mode='same')) model.add(Activation('tanh')) # ==================================================== model.compile('adam', loss='mean_squared_error') #model.compile('rmsprop', loss='mean_squared_error') return model