东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 5265|回复: 0
打印 上一主题 下一主题

[课堂笔记] 在多进程中使用keras报错Failed to get device properties, error code: 3

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14437
QQ
跳转到指定楼层
楼主
发表于 2020-4-18 09:54:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


在多进程中使用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)




让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-5-3 21:44 , Processed in 0.171100 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表