AttributeError: module ‘tensorflow._api.v1.compat‘ has no attribute ‘v1‘

AttributeError: module ‘tensorflow._api.v1.compat’ has no attribute ‘v1’

  • 猜测原因:TensorFlow不同版本的API有出入,用法不兼容
  • 解决:修改API即可。

将代码
config = tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.8
sess = tf.compat.v1.session(config=config)
 
 
改为
gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
config=tf.ConfigProto(gpu_options=gpu_options)
sess = tf.Session(config=config)

 
 
补充:
1.注意有三个地方的API都不同:①config;②gpu_options;③session
(其中,第二个如果不改,会报错:AttributeError: 'google.protobuf.pyext._message.FieldProperty' object has no attribute 'per_process_gpu_memory_fraction'

2.过程描述:一开始我直接在百度粘贴报错信息,但暂时没找到解决办法。后来直接搜索”tf.ConfigProto“查看其用法,对比不同版本tensorflow的API用法,才发现解决方法。

3.另外,有的文章可能说将import tensorflow as tf改为import tensorflow.compat.v1 as tf

但是我试了,会报错:ModuleNotFoundError: No module named 'tensorflow.compat.v1'
 
 

参考文章汇总

AttributeError: ‘google.protobuf.pyext._message.RepeatedScalarConta’ object has no attribute '_value

AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’

AttributeError: ‘google.protobuf.pyext._message.RepeatedScalarConta’ object has no attribute '_value

解决AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’

[机器学习]AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’ 报错解决方法

AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’

Tensorflow中tf.ConfigProto()详解

tensorflow学习笔记(二十五):ConfigProto&GPU

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值