Esempio n. 1
0
    def __init__(self,
                 encode_layers,
                 decode_layers,
                 size,
                 ch=3,
                 dp=0.0,
                 act=tf.nn.relu):

        self.size = size

        # encoder
        self.encoder = [
            create_layers(i, par) for i, par in enumerate(encode_layers)
        ]

        self.ef1 = fc(None, "f1", dropout=dp, act=act, bias=False)
        self.ef11 = fc(size, "f11", dropout=0.0, act=None, bias=False)

        self.ef2 = fc(None, "f2", dropout=dp, act=act, bias=False)
        self.ef21 = fc(size, "f21", dropout=dp, act=None, bias=False)

        self.decoder = [
            create_layers(i, par) for i, par in enumerate(decode_layers)
        ]
        self.df1 = fc(size, "f1", dropout=dp, act=act, bias=False)
Esempio n. 2
0
    def __create_variables(self, par, pre=''):

        h = [
            fc(x,
               '{}{}_h'.format(pre, i),
               act=par['h_act'],
               dropout=par['dp'],
               std=par['std']) for i, x in enumerate(par['hidden'])
        ]

        o = fc(par['size'],
               '{}_o'.format(pre),
               dropout=par['dp'],
               act=par['o_act'],
               std=par['std'])

        return h, o
Esempio n. 3
0
    def __init__(self,
                 conv_layers,
                 dconv_layers,
                 size,
                 dp=0.0,
                 act=tf.nn.relu):

        self.size = size

        # encoder
        self.encoder = [
            create_layers(i, par) for i, par in enumerate(conv_layers)
        ]

        self.ef1 = fc(None, "mu_h", dropout=dp, act=act, bias=True)
        self.ef11 = fc(size, "mu", dropout=0.0, act=None, bias=True)

        self.ef2 = fc(None, "logvar_h", dropout=dp, act=act, bias=True)
        self.ef21 = fc(size, "logvar", dropout=dp, act=None, bias=True)

        # decoder
        self.df1 = fc(size, "resample_h", dropout=dp, act=act, bias=True)
        self.df11 = fc(None, "resample", dropout=dp, act=None, bias=True)

        self.decoder = [
            create_layers(i, par) for i, par in enumerate(dconv_layers)
        ]
Esempio n. 4
0
def create_layers(index, par):

    if par['type'] == 'conv':
        return conv(par['out'],
                    par['k'],
                    par['s'],
                    "conv_layer_{}".format(index),
                    dropout=par['dp'],
                    bn=par['bn'],
                    act=par['act'],
                    bias=par['bias'])

    if par['type'] == 'se':
        return senet("se_layer_{}".format(index), act=par['act'])

    if par['type'] == 'sconv':
        return sconv(par['out'],
                     par['k'],
                     par['s'],
                     "sconv_layer_{}".format(index),
                     dropout=par['dp'],
                     bn=par['bn'],
                     act=par['act'])

    if par['type'] == 'dconv':
        return dconv(par['out'],
                     par['k'],
                     par['s'],
                     "dconv_layer_{}".format(index),
                     dropout=par['dp'],
                     bn=par['bn'],
                     act=par['act'],
                     bias=par['bias'])

    if par['type'] == 'fully':
        return fc(par['size'],
                  "fully_layer_{}".format(index),
                  dropout=par['dp'],
                  act=par['act'],
                  bias=par['bias'])
Esempio n. 5
0
    def __init__(self,
                 name,
                 size=64,
                 ch=3,
                 dp=0.0,
                 lr=1e-3,
                 decay_steps=1000,
                 decay_keep=.90,
                 bn=False,
                 num_heads=8,
                 act=tf.nn.relu):

        self.initial_learning_rate = lr
        self.decay_steps = decay_steps
        self.decay_keep = decay_keep
        self.size = size

        self.attn = attn_mh(ch, name, ch, num_heads, out_act=tf.nn.sigmoid)

        # encoder
        self.ec1 = conv(16,
                        3,
                        2,
                        "{}_c1".format(name),
                        dropout=dp,
                        bn=bn,
                        act=act,
                        bias=True)
        self.ec2 = conv(16,
                        3,
                        2,
                        "{}_c2".format(name),
                        dropout=dp,
                        bn=bn,
                        act=act,
                        bias=True)
        self.ec3 = conv(16,
                        3,
                        2,
                        "{}_c3".format(name),
                        dropout=dp,
                        bn=bn,
                        act=act,
                        bias=True)
        self.ec4 = conv(16,
                        3,
                        2,
                        "{}_c4".format(name),
                        dropout=dp,
                        bn=bn,
                        act=act,
                        bias=True)

        self.ef1 = fc(1024,
                      "{}_f1".format(name),
                      dropout=dp,
                      act=act,
                      bias=True)
        self.ef11 = fc(size,
                       "{}_f11".format(name),
                       dropout=dp,
                       act=None,
                       bias=True)

        self.ef2 = fc(1024,
                      "{}_f2".format(name),
                      dropout=dp,
                      act=act,
                      bias=True)
        self.ef21 = fc(size,
                       "{}_f21".format(name),
                       dropout=dp,
                       act=None,
                       bias=True)

        # decoder
        self.df2 = fc(1024,
                      "{}_f1".format(name),
                      dropout=dp,
                      act=act,
                      bias=True)
        self.df21 = fc(None,
                       "{}_f11".format(name),
                       dropout=dp,
                       act=act,
                       bias=True)

        self.dc1 = dconv(16,
                         3,
                         2,
                         "{}_c1".format(name),
                         dropout=dp,
                         bn=bn,
                         act=tf.nn.relu,
                         bias=True)
        self.dc2 = dconv(16,
                         3,
                         2,
                         "{}_c2".format(name),
                         dropout=dp,
                         bn=bn,
                         act=tf.nn.relu,
                         bias=True)
        self.dc3 = dconv(16,
                         3,
                         2,
                         "{}_c3".format(name),
                         dropout=dp,
                         bn=bn,
                         act=tf.nn.relu,
                         bias=True)
        self.dc4 = dconv(ch,
                         3,
                         2,
                         "{}_c4".format(name),
                         dropout=dp,
                         bn=bn,
                         act=tf.nn.sigmoid,
                         bias=True)