deep learning - How to reshape my data for the convolution neural network model? -


i need let input in convolution neural network model reshaping data, problem line of code:

model = sequential() input_traces = input(shape=(3253,)) model.add(convolution1d(nb_filter=32, filter_length=3,  activation='relu',input_shape = input_traces))       

this line gives me error:

   cnn_based_attack.py:139: userwarning: update `conv1d` call keras 2 api: `conv1d(activation="relu", input_shape=(none, /in..., padding="same", filters=32, kernel_size=3)`   model.add(convolution1d(nb_filter=32, filter_length=3, border_mode='same', activation='relu',input_dim=input_traces)) traceback (most recent call last):   file "cnn_based_attack.py", line 139, in <module>     model.add(convolution1d(nb_filter=32, filter_length=3, border_mode='same', activation='relu',input_dim=input_traces))   file "/home/.local/lib/python2.7/site-packages/keras/models.py", line 430, in add layer(x)   file "/home/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 557, in __call_self.build(input_shapes[0])   file "/home/.local/lib/python2.7/site-packages/keras/layers/convolutional.py", line 134, in build     constraint=self.kernel_constraint)   file "/home/.local/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 88, in wrapper return func(*args, **kwargs)   file "/home/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 390, in add_weight     weight = k.variable(initializer(shape), dtype=dtype, name=name)   file "/home/.local/lib/python2.7/site-packages/keras/initializers.py", line 200, in __call__     scale /= max(1., float(fan_in + fan_out) / 2) typeerror: float() argument must string or number 

when try mdify it:

model = sequential() model.add(convolution1d(nb_filter=32, filter_length=3,  activation='relu',input_shape = (500000, 3253)))         

it gives error:

/home/.local/lib/python2.7/site-packages/keras/models.py:834: userwarning: `nb_epoch` argument in `fit` has been renamed `epochs`.   warnings.warn('the `nb_epoch` argument in `fit` ' traceback (most recent call last):   file "cnn_based_attack.py", line 113, in <module>     model.fit(x_train, y_train, batch_size=15, nb_epoch=30)   file "/home/.local/lib/python2.7/site-packages/keras/models.py", line 853, in fit     initial_epoch=initial_epoch)   file "/home/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1424, in fit     batch_size=batch_size)   file "/home/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1300, in _standardize_user_data     exception_prefix='input')   file "/home/.local/lib/python2.7/site-packages/keras/engine/training.py", line 127, in _standardize_input_data     str(array.shape)) valueerror: error when checking input: expected conv1d_1_input have 3 dimensions, got array shape (500000, 3253) 

i don't know how resolve it.

i assume using old version of keras (since release 2.0, nb_filter has changed filters, therefore, should follow old documentation (e.g. this one) instead.

in first snippet, suppose problem in part: input_shape = input_traces. convolution1d constructor expects tuple, e.g. (32, 100, 3), input_traces initialized keras layer.

in second snipped, passed tuple instead, correct. errors says expects input_shape have 3 dimensions instead of 2. first, want point out nb_filter means 'number of filters per batch of data'. so, input_shape must include bach_size (in case if not familiar concept, there wonderful answer covers need know batches). so, pass

convolution1d(..., input_shape = (batch_size, data_length, numof_channels), ...) 

and should work (in case if wondering numof_channels, similar how image have 3 channels: red, green, , blue). if want have arbitrary bach_size, can pass input_shape = (none, data_length, numof_channels).


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -