I am a pretty new user of Keras. Recently I have started using it to train quite simple neural networks. I installed Keras, tensorflow-GPU, CUDA and CUDNN. Here is the code I am running :

all_mae_histories = []

for i in range(k):
    print('procesing fold #',i)
    val_targets=train_targets[i*num_val_samples: (i+1)*num_val_samples]

    partial_train_data = np.concatenate(
    partial_train_targets = np.concatenate(

    model = build_model()

    history= model.fit(partial_train_data, partial_train_targets, epochs=num_epochs,
    mae_history = history.history['mean_absolute_error']

average_mae_history=[np.mean([x[i] for x in all_mae_histories]) for i in range(num_epochs)]

basically, it is performing k-fold validation with 500 epochs and tracking the performance of the NN as a function of the epoch. Executing this code is quite long even though I have a NVIDIA 1060 graphic card. So I checked the load on the grapic card and it turned out that the code is using only 10% of the GPU and 50 % of each of my 8 CPU.

So my question is : how can I get Keras use the GPU rather than the CPU ? Would this lead to a faster execution ?



OK, I finally got this. Everything was fine. It is just that the use of the GPU depends on the type of task at hand. When working with larger batchs and larger datasets, my GPU reaches higher load. So I guess this is just normal.

New contributor
johnnyp is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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