当前位置:   article > 正文

解决tensorflow2.0版本的gpu内存占用问题(module ‘tensorflow‘ has no attribute ‘ConfigProto‘解决办法)_module 'tensorflow' has no attribute 'config

module 'tensorflow' has no attribute 'config

这个文章当作我学习tensorflow的一个笔记

当我们输入以下代码

import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.visible_device_list = '0'
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
  • 1
  • 2
  • 3
  • 4
  • 5

可能会出来
module ‘tensorflow’ has no attribute ‘ConfigProto’
原因之一是这个代码适用于tensorflow1.0版本,而电脑上安装的是2.0的版本
因此应该输入

import tensorflow as tf 
import os
os.environ['CUDA_VISIBLE_DEVICES']="0"
config=tf.compat.v1.ConfigProto() 
config.gpu_options.visible_device_list = '0' 
config.gpu_options.allow_growth = True 
sess=tf.compat.v1.Session(config=config)


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这样就解决了以上的问题

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号