Extremely slow CNN

I am trying to train a CNN with keras in R. I have a time series that is 3-dimensional, so every sample has dimensions 95 x 365 and has 80 features, which I feed in as channels. The output is only 1 value. The problem is that the net is extremely slow. Training the net for only 1 epoch with 400 samples takes 33 minutes. The architecture is very simple (I actually had a deeper net but since it was so slow I simplified it to see if that helps):

model - keras_model_sequential()
    model %% 
      layer_conv_2d(filters = 32, kernel_size = c(9, 9), activation = "relu",
                    input_shape = c(95, 365, 80)) %%
      layer_max_pooling_2d(pool_size = 2) %%
      layer_flatten() %%
      layer_dense(units = 50, activation = "relu") %%
      layer_dense(units=1)

    model %% compile(
      loss = 'mse',
      optimizer = optimizer_rmsprop()
    )

    model %% fit(
      x_train, y_train,
      batch_size = 32,
      epochs = 1,
      verbose = 0
    )

I really do not know what the issue is. I trained simpler networks such as MLPs and the computational time was in a "normal" range, like a few minutes for e.g. 100 epochs. So I guess the problem is not in the hardware I use.

Topic cnn keras

Category Data Science


If youre local environment is slowing down your training try using an online platform that provides you with free GPU's like Google Colab, Kaggle's Free GPU's

These are a few tutorials to use the same.


As CNN is computation expensive because of matrices calculation that's the point were GPU helps and when you perform the same operation on CPU it takes a lot of time as the number of core in CPU is far less than GPU.

As your data represented in 95x365 with 80 channels in them, the matrices operation making it slow

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.