chaohuazhu / facenet

Face recognition using Tensorflow
MIT License
0 stars 0 forks source link

facenet architecture #2

Open chaohuazhu opened 6 years ago

chaohuazhu commented 6 years ago

facenet hase two network architecture

  1. inception_resnet_v1
  2. inception_resnet_v2 def iception_resnet_v1(inputs,is_training=True, dropout_keep_prob=0.8, bottleneck_layer_size=128, reuse=None, scope='InceptionResNetV1'): bottleneck_layer_size is the full connect output size,and is the embedding size.

    构造计算图,prelogits为最后一层的输出

    prelogits, _ = network.inference(image_batch, args.keep_probability, 
        phase_train=phase_train_placeholder, bottleneck_layer_size=args.embedding_size,
        weight_decay=args.weight_decay)
    # 对最后的输出进行标准化,即为该图像的embedding
    embeddings = tf.nn.l2_normalize(prelogits, 1, 1e-10, name='embeddings')
    # Split embeddings into anchor, positive and negative and calculate triplet loss
    # 将输出的embeddings分为anchor,正样本, 负样本三个部分
    anchor, positive, negative = tf.unstack(tf.reshape(embeddings, [-1,3,args.embedding_size]), 3, 1)
    #根据上面三个部分计算triplet-loss
    
    triplet_loss = facenet.triplet_loss(anchor, positive, negative, args.alpha)
    #定义优化方法
    learning_rate = tf.train.exponential_decay(learning_rate_placeholder, global_step,
        args.learning_rate_decay_epochs*args.epoch_size, args.learning_rate_decay_factor, 
        staircase=True)
    tf.summary.scalar('learning_rate', learning_rate)
    
    # Calculate the total losses
    #加入正则化损失
    regularization_losses = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
    # 整体的损失即为triplet-loss+正则损失
    total_loss = tf.add_n([triplet_loss] + regularization_losses, name='total_loss')
    
    # Build a Graph that trains the model with one batch of examples and updates the model 
    # parameters
    # 用上述定义的优化方法和loss进行优化
    train_op = facenet.train(total_loss, global_step, args.optimizer, 
        learning_rate, args.moving_average_decay, tf.global_variables())