Deep Learning Practical Chapter (Seventeen) -- DenseNet of TensorFlow

Scientific knowledge

ACM International Conference on Multimedia (ACM International Conference on Multimedia) is the premier international conference on multimedia in the field of computer science. Multimedia studies focus on integrating the multiple perspectives provided by different digital modalities including images, text, video, music, sensor data, spoken audio. Since 1993, ACM Multimedia has been bringing together researchers and practitioners in academia and industry to present innovative research findings and discuss the latest advances.

# Preface #

    In the last article of the theoretical chapter, we learned about the DenseNet network structure. Although we did not carefully analyze the parameters of each layer, I believe that according to the previous progress and combined with the architecture given in the original paper, everyone should be able to easily The dimensionality change of each layer is inferred. The core of the network is feature multiplexing. Each layer in each dense block contains all the previous inputs, thus achieving the purpose of enriching feature representation and alleviating the problem of gradient disappearance to a certain extent.

TensorFlow's DenseNet combat

e2bce18f700ba22bbdbee8e896337f75.png

Next, we will share with you the facial expression recognition model based on the DenseNet network from data preparation to model construction. The model has been simplified, so please read it carefully!

1. Data preparation

This time the data uses the FERPlus facial expression dataset, which contains eight categories: peace, happiness, sadness, surprise, disgust, anger, and fear. Similar to the previous dataset, but with one more contemptuous expression.

3d74fb26d3990eac035fa615a8405ea1.png

2. Network structure

0d5a4542969e3bad2d8e416a3ae0719b.png

04c23441d22b4d135453f39b75871ab9.png

The minimum structure given in the original paper is 121 layers. We just started to learn, but there is no need to design such a deep structure. Therefore, we have slightly changed the structure of the corresponding figure above, and the main layer distribution has been changed from 6-12-24-16. It is 2-4-8-4, which can alleviate the problem of insufficient hardware to a certain extent. Of course, the accuracy will generally decrease, but it doesn’t matter. What we learn is the idea of ​​​​network construction rather than network construction. itself.

e1fb28e330af845d1f2df0d214afb629.png

# 密集块定义
def Dense_Block(name,input, inchannel, DB_nums):
    conv_inchannel = inchannel
    for i in range(DB_nums):
        out = Conv_layer('Dense_Block{}__1_{}'.format(name, i), input, [1,1,inchannel,32], [32], [1,1,1,1])
        # print("******** out1 {} ".format(out.shape))
        out = Conv_layer('Dense_Block{}__3_{}'.format(name, i), out, [3,3,32,32], [32], [1,1,1,1])
        # print("******** out2 {} ".format(out.shape))
        out = tf.concat([input, out], axis=3)
        inchannel = out.get_shape().as_list()[3]
        input = out


    return out


# 过渡层
def Transition_Layer(names, input):
     in_inchannel = input.get_shape().as_list()[3]
     out_channel = int(in_inchannel * 0.5)
     out = Conv_layer('Transition_Layer_{}'.format(names), input, [1,1,in_inchannel,out_channel], [out_channel], [1,1,1,1])
     out = Max_pool_lrn(names = 'pooling_{}'.format(names), input = out , ksize = [1, 3, 3, 1], is_lrn = False)


     return out
    
    # print("******** out {} ".format(out.shape))


# 分类层
def Class_Layer(input, n_classes):
    out = tf.nn.avg_pool(input, ksize=[1,7,7,1],strides=[1,7,7,1],padding='SAME')
    out = tf.squeeze(out)
    print("******** out {} ".format(out.shape))
    with tf.variable_scope('softmax_linear') as scope:
        weights = tf.Variable(tf.truncated_normal(shape=[out.get_shape().as_list()[-1], n_classes], stddev=0.005, dtype=tf.float32),
                              name='softmax_linear', dtype=tf.float32)


        biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[n_classes]),
                             name='biases', dtype=tf.float32)


        out = tf.add(tf.matmul(out, weights), biases, name='softmax_linear')


    return out

Network code:

30fc8113b97d35721021fc4e685f03e1.png

For the network training, we will not share it for the time being. Everyone mainly remembers the DenseNet network.

The feature is feature reuse, and then build a deep neural network.

83cbaf67877f941e85720873de07a829.png

epilogue

The sharing of this issue is over here, everyone should go down and do practical operations. If you need the source code, you can reply in the background: article name + code request. For later articles, we will gradually use Pytorch for actual combat. I hope you all have a good mind Get ready.

Editor: Yueyi Lay | Review: Shiwai Lay

Past review

[Year-end Summary] Saying goodbye to the old and welcoming the new, 2020, let's start again

[Year-end summary] 2021, bid farewell to the old and welcome the new

[Year-end summary] Pay tribute to the distant 2021 and embrace a different 2022

43e47b819bce81ae51d086dd9d2920e8.gif

Guess you like

Origin blog.csdn.net/xyl666666/article/details/123469656