1. 模型简介
自编码器是无监督学习的重要的学习方法,因为,该模型实现神经网络学习恒等映射函数h,即 x = h(x)
2. 模型实现
# Auto-Encoder
#
# Author: HSW
# Date: 2018-05-06
#
import tensorflow as tf
import numpy as np
def axvier_init(fan_in, fan_out, constant = 1):
''' Initial weights '''
low = -constant + np.sqrt(6.0 / (fan_in + fan_out))
high = constant + np.sqrt(6.0 / (fan_in + fan_out))
return tf.random_uniform((fan_in, fan_out), minval = low, maxval = high, dtype = tf.float32)
class AutoEncoder(object):
def __init__(self, AutoEncoder_Shape = (128, 256, 128), transfer_function = tf.nn.softplus, optimizer = tf.train.AdamOptimizer()):
''' Constructor Funcion '''
self.LayerCnt = len(AutoEncoder_Shape)
self.AutoEncoder_Shape = AutoEncoder_Shape
self.transfer = transfer_function
self.weights = self.init_weights()
self.layers = self.init_layers()
self.total_loss = self.init_loss()
self.optimizer = optimizer.minimize(self.total_loss)
init = tf.global_variables_initializer()