I am trying to run 1 dimensional CNN in R using keras package. I am trying to create one-dimensional Convolutional Neural Network (CNN) architecture with the following specification
library(keras)
library(deepviz)
#create a neural network with a convolutional layer and train the model
model <- keras_model_sequential() %>%
layer_conv_1d(filters=32, kernel_size=4, activation="relu", input_shape=c(100, 10)) %>%
layer_max_pooling_1d(pool_size=2) %>%
layer_conv_1d(filters=64, kernel_size=4, activation="relu") %>%
layer_max_pooling_1d(pool_size=5) %>%
layer_conv_1d(filters=128, kernel_size=4, activation="relu") %>%
layer_max_pooling_1d(pool_size=5) %>%
layer_conv_1d(filters=256, kernel_size=4, activation="relu") %>%
layer_max_pooling_1d(pool_size=5) %>%
layer_dropout(rate=0.4) %>%
layer_flatten() %>%
layer_dense(units=100, activation="relu") %>%
layer_dropout(rate=0.2) %>%
layer_dense(units=1, activation="linear")
But it is giving me following error
Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: Negative dimension size caused by subtracting 4 from 1 for 'conv1d_20/conv1d' (op: 'Conv2D') with input shapes: [?,1,1,128], [1,4,128,256].
How to solve the error?
Another question, how to optimise the filters, kernel_size, pool_size, rate, units?
In my question input_shape=c(100, 10) is an arbitrary value. How to decide about the input size?
