当前位置:   article > 正文

Anaconda3环境使用TensorFlow报错解决记录 mistGPU_attributeerror: module 'tensorflow' has no attribu

attributeerror: module 'tensorflow' has no attribute 'layers

先上总结

主要是由于代码是基于tensorflow1.0编写的,目前最新的版本是2.0,版本更新比较大,很多方法已经改名,或者弃用。多数报错为 has no attribute 'xxx'

为确保高版本的TF支持低版本的TF代码,升级脚本加入了 compat.v1 模块。

此模块将以等效的 tf.compat.v1.foo 引用代替表单 tf.foo 的调用。

不过,建议您手动检查此类替代方案,并尽快将其迁移至 tf.* 命名空间(代替 tf.compat.v1.* 命名空间)中的新 API。

还有一些其他模块,新的版本中方法名有所变动

问题1 compare_ssim找不到

File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/util.py", line 5, in <module>

from skimage.measure import compare_ssim as ssim

模块已经改名

修改/home/mist/1DeepAdverserialRegulariser/ClassFiles/util.py

改为

from skimage.metrics import structural_similarity as ssim

问题2 cannot import name 'imresize'

Traceback (most recent call last):

File "Adversarial_Regulariser.py", line 3, in <module>

from ClassFiles.data_pips import LUNA

File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/data_pips.py", line 7, in <module>

from scipy.misc import imresize

ImportError: cannot import name 'imresize' from 'scipy.misc' (/home/mist/anaconda3/lib/python3.8/site-packages/scipy/misc/__init__.py)


imresize已经弃用。使用PIL中的方法代替:

from scipy.misc import imresize

改为

from PIL import Image

def reshape_pic(self, pic):

pic = ut.normalize_image(pic)

pic = imresize(pic, [128, 128]) 这行要修改

pic = ut.scale_to_unit_intervall(pic)

return pic

pic = imresize(pic, [128, 128])

改为

pic = np.array(Image.fromarray(pic).resize((128,128)))

问题3 has no attribute 'InteractiveSession'

Training Data found: 0

Evaluation Data found: 0

/home/mist/anaconda3/lib/python3.8/site-packages/odl/tomo/backends/skimage_radon.py:144: FutureWarning: 'filter' is a deprecated argument name for `iradon`. It will be removed in version 0.19. Please use 'filter_name' instead.

backproj = iradon(skimage_sinogram.asarray().T, theta,

Traceback (most recent call last):

File "Adversarial_Regulariser.py", line 37, in <module>

experiment = Experiment1(DATA_PATH, SAVES_PATH)

File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/Framework.py", line 120, in __init__

super(AdversarialRegulariser, self).__init__(data_path, saves_path)

File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/Framework.py", line 45, in __init__

self.sess = tf.InteractiveSession()

AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'

从compat.v1 模块引入

self.sess = tf.InteractiveSession()

改为

self.sess = tf.compat.v1.InteractiveSession()

问题4 has no attribute 'placeholder'

2021-09-15 19:29:35.788948: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 9649 MB memory: -> device: 0, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:03:00.0, compute capability: 7.5

Traceback (most recent call last):

File "Adversarial_Regulariser.py", line 37, in <module>

experiment = Experiment1(DATA_PATH, SAVES_PATH)

File "/home/mist/1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/438691
推荐阅读
相关标签
  

闽ICP备14008679号