def __init__(self, X, multi_label: bool, nbChannels: int, nbCategories: int, _keep_proba): self.leNet_bottom = bricks.LeNet_bottom(X, nbChannels) """""" """on récupère la sortie de leNet_bottom""" h_pool2 = self.leNet_bottom.pool2 ''' On connecte les 7*7*64 neurones à une nouvelle couche de 1024 neurons fc signifie : fully connected. ''' W_fc1 = ing.weight_variable([7 * 7 * 64, 1024]) b_fc1 = ing.bias_variable([1024]) h_pool2_flat = tf.reshape(h_pool2, [-1, 7 * 7 * 64]) h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1) """dropout pour éviter le sur-apprentissage""" h_fc1_drop = tf.nn.dropout(h_fc1, _keep_proba) ''' on connecte les 1024 neurons avec nbCategories neurones de sorties''' W_fc2 = ing.weight_variable([1024, nbCategories]) b_fc2 = ing.bias_variable([nbCategories]) if multi_label: ''' sigmoid produit un vecteur dont chaque composante est une proba''' self.Y = tf.nn.sigmoid(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) else: '''softmax produit un vecteur de probabilité (la somme des composantes fait 1)''' self.Y = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)
def __init__(self, X, _keep_proba, nbChannels: int, nbCategories: int, nbRegressor: int): leNet_bottom = bricks.LeNet_bottom(X, nbChannels) """on récupère la sortie de leNet_bottom""" h_pool2 = leNet_bottom.pool2 W_fc1 = ing.weight_variable([7 * 7 * 64, 1024]) b_fc1 = ing.bias_variable([1024]) h_pool2_flat = tf.reshape(h_pool2, [-1, 7 * 7 * 64]) h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1) h_fc1_drop = tf.nn.dropout(h_fc1, _keep_proba) ''' on connecte les 1024 neurons avec nbCategories neurones de sorties''' W_fc2 = ing.weight_variable([1024, nbCategories]) b_fc2 = ing.bias_variable([nbCategories]) self.Y_prob = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) self.Y_cat = tf.arg_max(self.Y_prob, dimension=1) ''' on connecte les 1024 neurons avec nbRegressor neurones de sorties''' W_fc_reg = ing.weight_variable([1024, nbRegressor]) b_fc_reg = ing.bias_variable([nbRegressor]) tf.summary.histogram("b_fc2", b_fc2) tf.summary.histogram("b_fc1", b_fc1) tf.summary.histogram("W_fc2", W_fc2) tf.summary.histogram("W_fc1", W_fc1) self.Y_bound = tf.matmul(h_fc1_drop, W_fc_reg) + b_fc_reg
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)