AttributeError: 模块“tensorflow"没有属性“ConfigProto" [英] AttributeError: module 'tensorflow' has no attribute 'ConfigProto'
本文介绍了AttributeError: 模块“tensorflow"没有属性“ConfigProto"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我导入 tensorflow(版本 1.13.1)并且需要 ConfigProto
:
I import tensorflow (version 1.13.1) and need ConfigProto
:
import tensorflow as tf
config = tf.ConfigProto(intra_op_parallelism_threads=8,
inter_op_parallelism_threads=8,
allow_soft_placement=True,device_count = {'CPU' : 1, 'GPU' : 1})
我收到此错误:
AttributeError: module 'tensorflow' has no attribute 'ConfigProto'
我该如何解决这个问题?
How do I resolve this?
推荐答案
ConfigProto 在 tf 2.0 中消失了,所以一个优雅的解决方案是:
ConfigProto disappeared in tf 2.0, so an elegant solution is:
import tensorflow as tf
然后替换:
tf.ConfigProto
由 tf.compat.v1.ConfigProto
其实2.0内置的兼容性让tf 1.XX:tf.compat.v1
真的很有帮助.
In fact, the compatibility built in 2.0 to get tf 1.XX: tf.compat.v1
is really helpful.
有用的链接:将您的 tensorflow 1. 代码迁移到 tensorflow 2.:https://www.tensorflow.org/guide/migrate
Useful link: Migrate your tensorflow 1. code to tensorflow 2.: https://www.tensorflow.org/guide/migrate
这篇关于AttributeError: 模块“tensorflow"没有属性“ConfigProto"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文