Reputation: 475
I am trying to create a 1D Convolutional model using TensorFlow with a window size of 200 and so that each window overlaps by 50%.
I hope this is a simple fix, because I think that it is just the stride parameter but I am not sure.
This is my current code where I loop through a few convolution layers (conv_sizes). Groups is equal to 1 for each convolution layer as well.
(Ignore the 'self.' as I am assigning the conv_sizes to a model class)
window = 200
pad = int(window/2)
conv_sizes = [40, 30, 20]
groups = [1, 1, 1]
...
cur_layer = nn.Conv1d(self.conv_sizes[i], self.conv_sizes[i+1], kernel_size=window,
groups=groups[i], stride=1, padding=pad)
It currently operates by going window by window, and I think that the stride = 1 needs to be changed.
But I want to make sure I am in the right direction. Would I just switch the stride = 1 to 0.5? Or is it the groups parameter?
Help and an explanation would be great.
Upvotes: 0
Views: 380
Reputation: 80
I apologize if this is incorrect; I am rather new to this as well.
Stride in a convolution layer tells the layer how much to shift the filter.
Stride 1:
Stride 2:
Hence, it is not really possible to set stride to 0.5, as that would lead to an "in-between" where data does not exist without interpolation.
With a current stride of 1 and a window of 200, your convolution is doing something like this, where the "overlap" is 199/200 points, or 99.5%.:
If you want 50% data overlap, then you want a stride size of kernel_size * 0.5 = 100.
Upvotes: 2