Keras: How to control the number of threads when running sequential with Keras

Created on 16 Dec 2016  路  2Comments  路  Source: keras-team/keras

I try to run sequential with Keras; I found that the thread running sequential model generated about 13 sub-threads. How to control the number of sub-threads?

part of my code:
model = Sequential()
model.add(...)
.....
model.compile(loss='binary_crossentropy', optimizer=params['optimizer'])
model.fit(.....)

Please help me with this problem. Thanks in advance!

stale

Most helpful comment

This is what I use.

from keras import backend as K
import tensorflow as tf

config = tf.ConfigProto(intra_op_parallelism_threads=args.jobs, \ 
                        inter_op_parallelism_threads=args.jobs, \
                        allow_soft_placement=True, \
                        device_count = {'CPU': args.jobs})
session = tf.Session(config=config)
K.set_session(session)

All 2 comments

More detail to be added, the backbench for my Keras is Tensor Flow.

This is what I use.

from keras import backend as K
import tensorflow as tf

config = tf.ConfigProto(intra_op_parallelism_threads=args.jobs, \ 
                        inter_op_parallelism_threads=args.jobs, \
                        allow_soft_placement=True, \
                        device_count = {'CPU': args.jobs})
session = tf.Session(config=config)
K.set_session(session)
Was this page helpful?
0 / 5 - 0 ratings