使用TensorFlow双流卷积神经网络对CK+表情数据库进行分类

本文介绍了使用TensorFlow构建双流卷积神经网络对CK+表情数据库进行分类的方法,包括时间流和空间流的卷积处理,以及如何融合两流信息以提升识别效果。代码已上传至GitHub,并提供了CK+数据库的获取途径。
摘要由CSDN通过智能技术生成

本文所有代码已经放在GitHub上https://github.com/zhuzhuxia1994/CK-TensorFlow

双流卷积神经网络我最初是在做行为识别的时候接触到的,双流指的是时间流和空间流,再具体一点就是,时间流指的是对光流图片进行卷积处理,然后空间流指的是对RGB图片进行卷积处理,然后进行融合操作。这样往往比单纯对RGB图片进行卷积效果好,特别是在视频行为识别等方面,因为引入了时间信息。话不多说,放上代码及讲解。

以下代码是对表情识别CK+数据库进行实验,CK=数据库的地址如下http://www.consortium.ri.cmu.edu/ckagree/ 需要填写信息,如果有同学需要可以在博客下面留言,我会放上百度云地址~(先赞再跟我要哦,不然不理你,嘿嘿嘿害羞害羞

 import tensorflow as tf

#%%
def inference(s_images,T_images, batch_size, n_classes):
    '''Build the model
    Args:
        images: image batch, 4D tensor, tf.float32, [batch_size, width, height, channels]
    Returns:
        output tensor with the computed logits, float, [batch_size, n_classes]
    '''
    #conv1, shape = [kernel size, kernel size, channels, kernel numbers]
    
    # one stream space
    with tf.variable_scope('s_conv1') as scope:
        weights = tf.get_variable('weights', 
                                  shape = [3,3,3, 16],
                                  dtype = tf.float32, 
                                  initializer=tf.truncated_normal_initializer(stddev=0.1,dtype=tf.float32))
        biases = tf.get_variable('biases', 
                                 shape=[16],
                                 dtype=tf.float32,
                                 initializer=tf.constant_initializer(0.1))
        conv = tf.nn.conv2d(s_images, weights, strides=[1,1,1,1], padding='SAME')
        pre_activation = tf.nn.bias_add(conv, biases)
        s_conv1 = tf.nn.relu(pre_activation, name= scope.name)
    
    #pool1 and norm1   
    with tf.variable_scope('s_pooling1_lrn') as scope:
        pool1 = tf.nn.max_pool(s_conv1, ksize=[1,3,3,1],strides=[1,2,2,1],
                               padding='SAME', name='s_pooling1')
        norm1 = tf.nn.lrn(pool1, depth_radius=4, bias=1.0, alpha=0.001/9.0,
                          beta=0.75,name='s_norm1')
    
    #conv2
    with tf.variable_scope('s_conv2') as scope:
        weights = tf.get_variable('weights',
                                  shape=[3,3,16,16],
                                  dtype=tf.float32,
                                  initializer=tf.truncated_normal_initializer(stddev=0.1,dtype=tf.float32))
        biases = tf.get_variable('biases',
                                 shape=[16], 
                                 dtype=tf.float32,
                                 initializer=tf.constant_initializer(0.1))
        conv = tf.nn.conv2d(norm1, weights, strides=[1,1,1,1],padding='SAME')
        pre_activation = tf.nn.bias_add(conv, biases)
        s_conv2 = tf.nn.relu(pre_activation, name='s_conv2')
    
    
    #pool2 and norm2
    with tf.variable_scope('s_pooling2_lrn') as scope:
        norm2 = tf.nn.lrn(s_conv2, depth_radius=4, bias=1.0, alpha=0.001/9.0,
                          beta=0.75,name='s_norm2')
        pool2 = tf.nn.max_pool(norm2, ksize=[1,3,3,1], strides=[1,1,1,1],
                               padding='SAME',name='s_pooling2')
    
    
    #local3
    with tf.variable_scope('s_local3') as scope:
        reshape = tf.reshape(pool2, shape=[batch_size, -1])
        dim = reshape.get_shape()[1].value
        weights = tf.get_variable('weights',
                                  shape=[dim,128],
                                  dtype=tf.float32,
 
  • 56
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 77
    评论
评论 77
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值