Conversion neural network Conv1d input form

I am trying to create CNN to classify data. My data: X [N_data, N_features] I want to create a neural network that can classify it. My problem is with the Conv1D input form for the back of keras.

I want to repeat the filter. Let 10 functions, and then keep the same weights for the next ten functions. For each of the data, my convolutional layer created N_features / 10 New neurons. How can i do this? What should I enter in input_shape?

def cnn_model(): model = Sequential() model.add(Conv1D(filters=1, kernel_size=10 ,strides=10, input_shape=(1, 1,N_features),kernel_initializer= 'uniform', activation= 'relu')) model.flatten() model.add(Dense(N_features/10, init= 'uniform' , activation= 'relu' )) 

Any tips? thanks!

+5
source share
2 answers
Answer to

@Marcin may work, but there may be a suggestion given here:

When using this layer as the first layer in the input_shape model (a tuple of integers or None, for example (10, 128) for a sequence of 10 vectors of 128-dimensional vectors or (no, 128) for a sequence with a variable length of 128-dimensional vectors.

:

 model = Sequential() model.add(Conv1D(filters=1, kernel_size=10 ,strides=10, input_shape=(None, N_features),kernel_initializer= 'uniform', activation= 'relu')) 

Please note that starting from the input data (N_Data, N_features) we set the number of examples as indefinite (None). The strides argument controls the size of the timestamps in this case.

+2
source

Try:

 def cnn_model(): model = Sequential() model.add(Conv1D(filters=1, kernel_size=10 ,strides=10, input_shape=(N_features, 1),kernel_initializer= 'uniform', activation= 'relu')) model.flatten() model.add(Dense(N_features/10, init= 'uniform' , activation= 'relu' )) .... 

And change form x to form (nb_of_examples, nb_of_features, 1) .

EDIT:

Conv1D was designed for sequence analysis — having convolutional filters that are the same no matter where in the sequence we are. The second dimension is the so-called features, where you can have a vector with several functions on each of the timestamps. You can think of the dimension of a sequence as well as the spatial dimensions and dimension of an object, the same as the channel size or color size in Conv2D . As mentioned by @putonspectacles in your comment, you can set the size of the None sequence to make your input network length invariant.

+6
source

Source: https://habr.com/ru/post/1266373/


All Articles