Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use tensorflow.GPUOptions within Keras when using tensorflow backend

In tensorflow I can do something like this when creating a session:

tf.GPUOptions(per_process_gpu_memory_fraction=0.333,allow_growth=True)

Is there a way to do the same in keras with the tensorflow backend?

like image 363
Andi Avatar asked Jan 20 '17 11:01

Andi


People also ask

Is TensorFlow backend for Keras?

Keras used to use 2 backends(Theano and Tensorflow), but now only supports Tensorflow because of the discontinuation of Theano. The reason why Keras uses Tensorflow as it's backend is because it is an abstraction layer.

What does Keras backend Clear_session () do?

clear_session functionResets all state generated by Keras. Keras manages a global state, which it uses to implement the Functional model-building API and to uniquify autogenerated layer names.

What is Keras backend function?

What is a "backend"? Keras is a model-level library, providing high-level building blocks for developing deep learning models. It does not handle itself low-level operations such as tensor products, convolutions and so on.


1 Answers

You can set the Keras global tensorflow session with keras.backend.tensorflow_backend.set_session():

import tensorflow as tf
import keras.backend.tensorflow_backend as ktf


def get_session(gpu_fraction=0.333):
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction,
                                allow_growth=True)
    return tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))


ktf.set_session(get_session())
like image 93
André Panisson Avatar answered Oct 15 '22 00:10

André Panisson