예제 #1
0
    def __init__(self, encoder: Encoder, Y_last_dim: int, keep_prob: float,
                 favoritism: tuple, depth0: int, depth1: int,
                 either_sig_softmax: bool):
        """"""
        """ on transforme le layer d'avant en un volume 7*7*depth0 par des conv 1*1"""
        with tf.variable_scope("smallConv0"):
            W = ing.weight_variable([1, 1, 64, depth0], name="W")
            b = ing.bias_variable([depth0], name="b")

            conv = tf.nn.conv2d(
                encoder.Y, W, strides=[1, 1, 1, 1], padding="SAME") + b
            relu = tf.nn.relu(conv, name="relu")
            relu_dropout = tf.nn.dropout(relu,
                                         keep_prob=keep_prob,
                                         name="dropout")
        """ on transforme le layer d'avant en un volume 7*7*nbCategories par des conv 1*1"""
        with tf.variable_scope("smallConv1"):
            W = ing.weight_variable([1, 1, depth0, depth1], name="W")
            b = ing.bias_variable([depth1], name="b")

            conv = tf.nn.conv2d(
                relu_dropout, W, strides=[1, 1, 1, 1], padding="SAME") + b
            relu = tf.nn.relu(conv, name="relu")
            relu_dropout = tf.nn.dropout(relu,
                                         keep_prob=keep_prob,
                                         name="dropout")
        """  DANS LA SUITE : on dilate les images 7*7 pour revenir à la résolution initiale 28*28  """
        """ 7*7*depth1 ---> 14*14*32 """
        with tf.variable_scope("dilate0"):
            """  [height, width, output_channels, in_channels=nbCategories] """
            W = tf.Variable(initial_value=ing.get_bilinear_initial_tensor(
                [4, 4, 32, depth1], 2),
                            name='W')
            b = ing.bias_variable([32], name="b")
            upConv0 = ing.up_convolution(relu_dropout, W, 2, 2) + b
            """on y ajoute le milieu de leNet (14*14*32 aussi)"""
            fuse_1 = upConv0 + encoder.pool1

            ing.summarizeW_asImage(W)
        """on dilate maintenant fuse_1 pour atteindre la résolution des images d'origine
           14*14*32 ----> 28*28*nbCategories
        """
        with tf.variable_scope("dilate1"):
            W = tf.Variable(initial_value=ing.get_bilinear_initial_tensor(
                [4, 4, Y_last_dim, 32], 2),
                            name='W')
            b = ing.bias_variable([Y_last_dim], name="b")

            ing.summarizeW_asImage(W)
        """ les logits (on y applique pas le softmax car plus loin on peut éventuellement utiliser tf.nn.sparse_softmax_cross_entropy_with_logits) """
        self.Y_logits = ing.up_convolution(fuse_1, W, 2, 2) + b

        if either_sig_softmax: self.Y_proba = tf.nn.sigmoid(self.Y_logits)
        else: self.Y_proba = tf.nn.softmax(self.Y_logits)

        self.Y_cat_sum = tf.reduce_sum(self.Y_proba, axis=3)
예제 #2
0
    def __init__(self, X, nbChannels: int, nbCategories: int, keep_prob,
                 favoritism):
        """"""
        """on récupère le réseau très simple: leNet_bottom"""
        leNet = bricks.LeNet_bottom(X, nbChannels)
        """la sorties est un volume 7*7*64.  """
        """ DANS LA SUITE: on recopie leNet, mais en remplaçant les fully-connected par des convolutions 1*1  """
        """ on transforme le layer d'avant en un volume 7*7*1024 par des conv 1*1"""
        with tf.variable_scope("smallConv0"):
            W = ing.weight_variable([1, 1, 64, 1024], name="W")
            b = ing.bias_variable([1024], name="b")

            conv = tf.nn.conv2d(
                leNet.Y, W, strides=[1, 1, 1, 1], padding="SAME") + b
            relu = tf.nn.relu(conv, name="relu")
            relu_dropout = tf.nn.dropout(relu,
                                         keep_prob=keep_prob,
                                         name="dropout")
        """ on transforme le layer d'avant en un volume 7*7*nbCategories par des conv 1*1"""
        with tf.variable_scope("smallConv1"):
            W = ing.weight_variable([1, 1, 1024, nbCategories], name="W")

            b = ing.bias_variable([nbCategories], name="b")

            conv = tf.nn.conv2d(
                relu_dropout, W, strides=[1, 1, 1, 1], padding="SAME") + b
            relu = tf.nn.relu(conv, name="relu")
            relu_dropout = tf.nn.dropout(relu,
                                         keep_prob=keep_prob,
                                         name="dropout")
        """  DANS LA SUITE : on dilate les images 7*7 pour revenir à la résolution initiale 28*28  """
        """ 7*7*nbCategories ---> 14*14*32 """
        with tf.variable_scope("dilate0"):
            """  [height, width, output_channels, in_channels=nbCategories] """
            W = tf.Variable(initial_value=ing.get_bilinear_initial_tensor(
                [4, 4, 32, nbCategories], 2),
                            name='W')
            b = ing.bias_variable([32], name="b")
            upConv0 = ing.up_convolution(relu_dropout, W, 2, 2) + b
            """on y ajoute le milieu de leNet (14*14*32 aussi)"""
            fuse_1 = upConv0 + leNet.pool1

            ing.summarizeW_asImage(W)
        """on dilate maintenant fuse_1 pour atteindre la résolution des images d'origine
           14*14*32 ----> 28*28*nbCategories
        """
        with tf.variable_scope("dilate1"):
            W = tf.Variable(initial_value=ing.get_bilinear_initial_tensor(
                [4, 4, nbCategories, 32], 2),
                            name='W')
            b = ing.bias_variable([nbCategories], name="b")

            ing.summarizeW_asImage(W)
        """ les logits (on y applique pas le softmax car plus loin on utilisera la loss tf.nn.sparse_softmax_cross_entropy_with_logits) """
        self.Y_logits = ing.up_convolution(fuse_1, W, 2, 2) + b

        self.Y_proba = tf.nn.softmax(self.Y_logits)
        """ chaque pixel reçoit la catégorie qui a la plus forte probabilité, en tenant compte du favoritisme."""
        self.Y_cat = tf.cast(
            tf.argmax(self.Y_proba * favoritism,
                      dimension=3,
                      name="prediction"), tf.int32)