Basic 1d convolution in tensorflow

后端 未结 3 1032
甜味超标
甜味超标 2020-12-13 06:59

OK, I\'d like to do a 1-dimensional convolution of time series data in Tensorflow. This is apparently supported using tf.nn.conv2d, according to these tickets,

3条回答
  •  死守一世寂寞
    2020-12-13 07:42

    In the new versions of TF (starting from 0.11) you have conv1d, so there is no need to use 2d convolution to do 1d convolution. Here is a simple example of how to use conv1d:

    import tensorflow as tf
    i = tf.constant([1, 0, 2, 3, 0, 1, 1], dtype=tf.float32, name='i')
    k = tf.constant([2, 1, 3], dtype=tf.float32, name='k')
    
    data   = tf.reshape(i, [1, int(i.shape[0]), 1], name='data')
    kernel = tf.reshape(k, [int(k.shape[0]), 1, 1], name='kernel')
    
    res = tf.squeeze(tf.nn.conv1d(data, kernel, stride=1, padding='VALID'))
    with tf.Session() as sess:
        print sess.run(res)
    

    To understand how conv1d is calculates, take a look at various examples

提交回复
热议问题