|
在多进程中使用keras报错Failed to get device properties, error code: 3
Use keras in multiprocessing
https://stackoverflow.com/questions/50289628/use-keras-in-multiprocessing
要在多个进程中使用keras模型,您必须执行以下操作:
建立模型
调用 _make_predict_function()
设置一个会话并使用它来获取tensorflow图
最终确定该图
每当您预测某事时,提供此图 as_default_graph()
# now to use it in multiprocessing, the following is necessary
model._make_predict_function()
sess = tf.Session()
sess.run(tf.global_variables_initializer())
default_graph = tf.get_default_graph()
default_graph.finalize()
# now you share the model and graph between processes
# in each process you can call this:
with default_graph.as_default():
return model.predict(something)
|
|