def __init__(
            self,
            output_act_func='softmax',
            hidden_act_func='relu',
            loss_func='cross_entropy',
            use_for='classification',
            lr=1e-3,
            epochs=100,
            img_shape=[28, 28],
            layer_tp=['C', 'C', 'P', 'C', 'P'],
            channels=[1, 6, 6, 64,
                      10],  # 输入1张图 -> 卷积池化成6张图 -> 卷积池化成6张图 -> 全连接层 -> 分类层
            fsize=[[4, 4], [3, 3]],
            ksize=[[2, 2], [2, 2]],
            batch_size=32,
            dropout=0):
        Model.__init__(self, 'CNN')
        self.hidden_act_func = hidden_act_func
        self.output_act_func = out_act_check(output_act_func, loss_func)
        self.loss_func = loss_func
        self.use_for = use_for
        self.lr = lr
        self.epochs = epochs
        self.channels = channels
        self.layer_tp = layer_tp
        self.img_shape = img_shape
        self.fsize = fsize
        self.ksize = ksize
        self.batch_size = batch_size
        self.dropout = dropout

        with tf.name_scope('CNN'):
            self.build_model()
Beispiel #2
0
 def __init__(self,
              output_act_func='softmax',
              loss_func='cross_entropy',
              use_for='classification',
              bp_algorithm='adam',
              lr=1e-3,
              momentum=0.9,
              epochs=100,
              width=5,
              struct=[784, 100 ,10],
              batch_size=32,
              dropout=0,
              variants=0):
     Model.__init__(self,'LSTM')
     self.loss_func=loss_func
     self.output_act_func = out_act_check(output_act_func,loss_func)
     self.use_for=use_for
     self.bp_algorithm=bp_algorithm
     self.lr=lr
     self.momentum=momentum
     self.epochs=epochs
     self.width=width
     self.struct = struct
     self.batch_size = batch_size
     self.dropout=dropout
     self.variants=variants
         
     if output_act_func=='gauss':
         self.loss_func='mse'
     self.output_act=act_func(self.output_act_func)
     
     self.build_model()
Beispiel #3
0
    def __init__(
            self,
            name='AE-1',
            loss_func='mse',  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
            ae_type='ae',  # ae | dae | sae
            act_type=['sigmoid', 'affine'],
            noise_type='gs',  # Gaussian noise (gs) | Masking noise (mn)
            beta=0.5,  # DAE:噪声损失系数 | SAE:稀疏损失系数
            p=0.5,  # DAE:样本该维作为噪声的概率 | SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)
            struct=[784, 100],
            out_size=10,
            ae_epochs=10,
            batch_size=32,
            lr=1e-3):
        Model.__init__(self, name)
        self.name = name
        self.loss_func = loss_func
        self.ae_type = ae_type

        self.noise_type = noise_type
        self.beta = beta
        self.alpha = 1 - self.beta
        self.p = p
        self.n_x = struct[0]
        self.n_h = struct[1]
        self.out_size = out_size
        self.epochs = ae_epochs
        self.batch_size = batch_size
        self.lr = lr
        self.momentum = 0.5

        self.en_func = act_type[0]
        self.de_func = out_act_check(act_type[1], loss_func)

        # sae: kl 要求 h 必须是0~1之间的数
        if ae_type == 'sae' and (act_type[0]
                                 not in ['softmax', 'sigmoid', 'gauss']):
            self.en_func = 'sigmoid'

        with tf.name_scope(self.name):
            self.build_model()
Beispiel #4
0
    def __init__(
            self,
            output_func='softmax',
            hidden_func='affine',  # encoder:[sigmoid] | [affine] 
            use_for='classification',
            loss_func='mse',  # decoder:[sigmoid] with ‘cross_entropy’ | [affine] with ‘mse’
            struct=[784, 100, 100, 10],
            lr=1e-4,
            epochs=60,
            batch_size=32,
            dropout=0,
            ae_type='dae',  # ae | dae | sae
            act_type=['sigmoid', 'affine'],
            noise_type='mn',  # Gaussian noise (gs) | Masking noise (mn)
            beta=0.25,  # 惩罚因子权重(KL项 | 非噪声样本项)
            p=0.5,  # DAE:样本该维作为噪声的概率 / SAE稀疏性参数:期望的隐层平均活跃度(在训练批次上取平均)      
            ae_lr=1e-3,
            ae_epochs=20,
            pre_train=True):
        Model.__init__(self, 'sup_sAE')
        self.hidden_func = hidden_func
        self.output_act_func = out_act_check(output_func, loss_func)

        self.use_for = use_for
        self.loss_func = loss_func
        self.struct = struct
        self.lr = lr
        self.epochs = epochs
        self.dropout = dropout
        self.pre_train = pre_train

        self.ae_type = ae_type
        self.act_type = act_type
        self.noise_type = noise_type
        self.beta = beta
        self.p = p
        self.ae_epochs = ae_epochs
        self.ae_lr = ae_lr
        self.batch_size = batch_size

        self.build_model()
Beispiel #5
0
    def __init__(
            self,
            hidden_act_func='relu',
            output_act_func='softmax',
            loss_func='mse',  # gauss 激活函数会自动转换为 mse 损失函数
            struct=[784, 100, 100, 10],
            lr=1e-4,
            momentum=0.5,
            use_for='classification',
            bp_algorithm='adam',
            epochs=100,
            batch_size=32,
            dropout=0.3,
            units_type=['gauss', 'bin'],
            rbm_lr=1e-3,
            rbm_epochs=30,
            cd_k=1,
            pre_train=True):
        Model.__init__(self, 'DBN')
        self.loss_func = loss_func
        self.hidden_act_func = hidden_act_func
        self.output_act_func = out_act_check(output_act_func, loss_func)
        self.use_for = use_for
        self.bp_algorithm = bp_algorithm
        self.lr = lr
        self.momentum = momentum
        self.epochs = epochs
        self.struct = struct
        self.batch_size = batch_size
        self.dropout = dropout
        self.pre_train = pre_train

        self.dbm_struct = struct[:-1]
        self.units_type = units_type
        self.cd_k = cd_k
        self.rbm_lr = rbm_lr
        self.rbm_epochs = rbm_epochs

        self.build_model()