简体   繁体   English

Tensorflow中的Conv1D混乱

[英]Conv1D confusion in Tensorflow

Trying to implement a paper and running into some brick-walls due to some dimensionality problems. 由于存在尺寸问题,试图实施纸张并碰到一些砖墙。 My input is mono audio data where 128 frames of 50ms of 16kHz sampled audio is fed into the network. 我的输入是单声道音频数据,其中128帧50ms的16kHz采样音频被馈送到网络中。 So my input shape is: [128,0.005*16000, 1] Here's the layer details - 所以我的输入形状是:[128,0.005 * 16000,1]这是图层详细信息-

1.) conv-bank block : Conv1d-bank-8, LeReLU, IN (instance normalization) I achieve this using : 1.)conv-bank块:Conv1d-bank-8,LeReLU,IN(实例规范化)我使用以下方法实现此目的:

bank_width = 8
conv_bank_outputs = tf.concat([ tf.layers.conv1d(input,1,k,activation=tf.nn.leaky_relu,padding="same") for k in range(1, bank_width + 1)], axes = -1)

2.) conv-block: C-512-5, LReLu --> C-512-5,stride=2, LReLu, IN, RES (Residual) 2.)conv-block:C-512-5,LReLu-> C-512-5,stride = 2,LReLu,IN,RES(剩余)

This is where I get stuck, the shapes of the output of second convolution and input to the (2) layer is mismatched. 这是我卡住的地方,第二次卷积的输出和(2)层的输入的形状不匹配。 I can't get my head around it. 我无法解决这个问题。

I achieve this using: 我使用以下方法实现此目的:

block_1 = tf.layers.conv1d(input,filters=512,kernel_size=5,activation=tf.nn.leaky_relu,padding="same")
block_2 = tf.layers.conv1d(block_1,filters=512,kernel_size=5,strides=2,activation=tf.nn.leaky_relu,padding="same")
IN = tf.contrib.layers.instance_norm(block_2)
RES = IN + input

Error: ValueError: Dimensions must be equal, but are 400 and 800 for 'add' (op: 'Add') with input shapes: [128,400,512], [128,800,1024]. 错误: ValueError: Dimensions must be equal, but are 400 and 800 for 'add' (op: 'Add') with input shapes: [128,400,512], [128,800,1024].

When you run conv1d on block1 with stride = 2 , input data is halved as conv1d effectively samples only alternate numbers and also you have changed number of channels. 当您在具有stride = 2的block1上运行conv1d时,输入数据将减半,因为conv1d仅有效地采样了备用数字,并且您更改了通道数。 This is usually worked around by downsampling input by 1x1 conv with stride 2 and filters 512, though I can be more specific if you can share the paper. 这通常可以通过使用跨步2和过滤器512通过1x1 conv对输入进行下采样来解决,尽管如果可以共享纸张,我可以更具体一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM