0
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ The network you define above has quite a lot of parameters (which you can check using summary(model)) given that the input shape is (95, 365, 80) and you are using only 1 convolutional layers and 1 pooling layer. One way to decrease the number of parameter would be to increase the number of convolutional and pooling layers in your network. $\endgroup$
    – Oxbowerce
    Mar 16, 2020 at 11:21

2 Answers 2

1
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ I guess it is a dumb quesstion, but how can I use GPU? Or how do I know which one I am using? $\endgroup$
    – msloryg
    Jun 23, 2019 at 9:38
  • $\begingroup$ In the case of keras, you don't have to manually set GPU usage if GPU is available it starts using it. $\endgroup$ Jun 24, 2019 at 6:05
  • 1
    $\begingroup$ @msloryg That is not true, you need to have tensorflow-gpu installed in order to take advantage of your GPU $\endgroup$
    – Nikos H.
    Jul 20, 2019 at 13:16
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.