基于基于Tensorflow一维卷积用法详解一维卷积用法详解
主要介绍了基于Tensorflow一维卷积用法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来
看看吧
我就废话不多说了,大家还是直接看代码吧!
import tensorflow as tf
import numpy as np
input = tf.constant(1,shape=(64,10,1),dtype=tf.float32,name='input')#shape=(batch,in_width,in_channels)
w = tf.constant(3,shape=(3,1,32),dtype=tf.float32,name='w')#shape=(filter_width,in_channels,out_channels)
conv1 = tf.nn.conv1d(input,w,2,'VALID') #2为步长
print(conv1.shape)#宽度计算(width-kernel_size+1)/strides ,(10-3+1)/2=4 (64,4,32)
conv2 = tf.nn.conv1d(input,w,2,'SAME') #步长为2
print(conv2.shape)#宽度计算width/strides 10/2=5 (64,5,32)
conv3 = tf.nn.conv1d(input,w,1,'SAME') #步长为1
print(conv3.shape) # (64,10,32)
with tf.Session() as sess:
print(sess.run(conv1))
print(sess.run(conv2))
print(sess.run(conv3))
以下是input_shape=(1,10,1), w = (3,1,1)时,conv1的shape
以下是input_shape=(1,10,1), w = (3,1,3)时,conv1的shape
补充知识:补充知识:tensorflow中一维卷积中一维卷积conv1d处理语言序列举例处理语言序列举例
评论0