Anaconda3环境使用TensorFlow报错解决记录 mistGPU
先上总结
主要是由于代码是基于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/1DeepAdverserialRegulariser/ClassFiles/Framework.py", line 127, in __init__
self.gen_im = tf.placeholder(shape=[None, self.image_space[0], self.image_space[1], self.colors],
AttributeError: module 'tensorflow' has no attribute 'placeholder'
从compat.v1 模块引入
import tensorflow as tf
改为
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
问题 5 has no attribute 'layers'
2021-09-15 19:34:42.613666: 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/1DeepAdverserialRegulariser/ClassFiles/Framework.py", line 137, in __init__
self.gen_was = self.network.net(self.gen_im)
File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/networks.py", line 91, in net
conv1 = tf.layers.conv2d(inputs=input, filters=16, kernel_size=[5, 5], padding="same",
AttributeError: module 'tensorflow' has no attribute 'layers'
从compat.v1 模块引入
修改
class ConvNetClassifier(network):
# classical classifier with convolutional layers with strided convolutions and two dense layers at the end
def net(self, input):
# convolutional network for feature extraction
tf.layers = tf.compat.v1.layers 增加这行,猴子补丁
conv1 = tf.layers.conv2d(inputs=input, filters=16, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv1')
conv2 = tf.layers.conv2d(inputs=conv1, filters=32, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv2')
conv3 = tf.layers.conv2d(inputs=conv2, filters=32, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv3', strides=2)
# image size is now size/2
conv4 = tf.layers.conv2d(inputs=conv3, filters=64, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv4', strides=2)
# image size is now size/4
conv5 = tf.layers.conv2d(inputs=conv4, filters=64, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv5', strides=2)
# image size is now size/8
conv6 = tf.layers.conv2d(inputs=conv5, filters=128, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv6', strides=2)
问题6 has no attribute 'AUTO_REUSE'
module 'tensorflow' has no attribute 'AUTO_REUSE'
从compat.v1 模块引入
class ConvNetClassifier(network):
# classical classifier with convolutional layers with strided convolutions and two dense layers at the end
def net(self, input):
# convolutional network for feature extraction
tf.layers = tf.compat.v1.layers
tf.AUTO_REUSE = tf.compat.v1.AUTO_REUSE 增加这行。新增猴子补丁
conv1 = tf.layers.conv2d(inputs=input, filters=16, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv1')
conv2 = tf.layers.conv2d(inputs=conv1, filters=32, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv2')
conv3 = tf.layers.conv2d(inputs=conv2, filters=32, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv3', strides=2)
# image size is now size/2
conv4 = tf.layers.conv2d(inputs=conv3, filters=64, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv4', strides=2)
# image size is now size/4
conv5 = tf.layers.conv2d(inputs=conv4, filters=64, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv5', strides=2)
# image size is now size/8
conv6 = tf.layers.conv2d(inputs=conv5, filters=128, kernel_size=[5, 5], padding="same",
activation=lrelu, reuse=tf.AUTO_REUSE, name='conv6', strides=2)
问题7 has no attribute 'get_default_graph'
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 174, in __init__
self.ray = self.model.tensorflow_operator(self.reconstruction)
File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/forward_models.py", line 103, in tensorflow_operator
return self.ray_transform(tensor)
File "/home/mist/anaconda3/lib/python3.8/site-packages/odl/contrib/tensorflow/layer.py", line 369, in tensorflow_layer
result = py_func(_impl,
File "/home/mist/anaconda3/lib/python3.8/site-packages/odl/contrib/tensorflow/layer.py", line 99, in py_func
g = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
修改源码文件:/home/mist/anaconda3/lib/python3.8/site-packages/odl/contrib/tensorflow/layer.py
在前面增加这行:tf.get_default_graph = tf.compat.v1.get_default_graph
猴子补丁:
如图下所示:
问题8 has no attribute 'py_func'
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
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 174, in __init__
self.ray = self.model.tensorflow_operator(self.reconstruction)
File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/forward_models.py", line 103, in tensorflow_operator
return self.ray_transform(tensor)
File "/home/mist/anaconda3/lib/python3.8/site-packages/odl/contrib/tensorflow/layer.py", line 371, in tensorflow_layer
result = py_func(_impl,
File "/home/mist/anaconda3/lib/python3.8/site-packages/odl/contrib/tensorflow/layer.py", line 104, in py_func
return tf.py_func(func, inp, Tout, stateful=stateful,
AttributeError: module 'tensorflow' has no attribute 'py_func'
修改源码文件:/home/mist/anaconda3/lib/python3.8/site-packages/odl/contrib/tensorflow/layer.py
在前面增加这行:tf.py_func=tf.compat.v1.py_func
如图下所示
astra-toolbox 模块安装
使用conda命令安装即可
conda install -c astra-toolbox/label/dev astra-toolbox
安装详情打印如下:
$ conda install -c astra-toolbox/label/dev astra-toolbox Collecting package metadata (current_repodata.json): / done Solving environment: - The environment is inconsistent, please check the package plan carefully The following packages are causing the inconsistency:- defaults/noarch::seaborn==0.11.1=pyhd3eb1b0_0- defaults/linux-64::scipy==1.6.2=py38had2a1c9_1- defaults/linux-64::anaconda==2021.05=py38_0- defaults/linux-64::pywavelets==1.1.1=py38h7b6447c_2- defaults/linux-64::patsy==0.5.1=py38_0- defaults/linux-64::pandas==1.2.4=py38h2531618_0- defaults/linux-64::statsmodels==0.12.2=py38h27cfd23_0- defaults/linux-64::numba==0.53.1=py38ha9443f7_0- defaults/linux-64::pyerfa==1.7.3=py38h27cfd23_0- defaults/linux-64::bottleneck==1.3.2=py38heb32a55_1- defaults/linux-64::pytables==3.6.1=py38h9fd0a39_0- defaults/linux-64::astropy==4.2.1=py38h27cfd23_1- defaults/linux-64::mkl_fft==1.3.0=py38h42c9631_2- defaults/linux-64::tifffile==2020.10.1=py38hdd07704_2- defaults/linux-64::matplotlib==3.3.4=py38h06a4308_0- defaults/linux-64::scikit-learn==0.24.1=py38ha9443f7_0- defaults/linux-64::matplotlib-base==3.3.4=py38h62a2d02_0- defaults/linux-64::bokeh==2.3.2=py38h06a4308_0- defaults/linux-64::bkcharts==0.2=py38_0- defaults/linux-64::mkl_random==1.2.1=py38ha9443f7_2- defaults/noarch::imageio==2.9.0=pyhd3eb1b0_0- defaults/noarch::dask==2021.4.0=pyhd3eb1b0_0- defaults/linux-64::numexpr==2.7.3=py38h22e1b3c_1- defaults/linux-64::numpy==1.20.1=py38h93e21f0_0- defaults/linux-64::scikit-image==0.18.1=py38ha9443f7_0 done==> WARNING: A newer version of conda exists. <==current version: 4.10.1latest version: 4.10.3Please update conda by running$ conda update -n base -c defaults conda## Package Plan ##environment location: /home/mist/anaconda3added / updated specs:- astra-toolboxThe following packages will be downloaded:package | build---------------------------|-----------------_anaconda_depends-2020.07 | py38_0 6 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainanaconda-custom | py38_1 35 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainastra-toolbox-1.9.9.dev7 | py38h9d24096_0 432 KB astra-toolbox/label/devcudatoolkit-10.2.89 | hfd86e86_1 365.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainh5py-2.10.0 | py38h7918eee_0 1.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainlibllvm9-9.0.1 | he513fc3_1 25.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forgenumpy-base-1.20.1 | py38h7d8b39e_0 4.6 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainopenssl-1.1.1l | h7f8727e_0 2.5 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainpathtools-0.1.2 | py_1 8 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forgesnappy-1.1.8 | he1b5a44_3 32 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge------------------------------------------------------------Total: 398.8 MBThe following NEW packages will be INSTALLED:_anaconda_depends anaconda/pkgs/main/linux-64::_anaconda_depends-2020.07-py38_0astra-toolbox astra-toolbox/label/dev/linux-64::astra-toolbox-1.9.9.dev7-py38h9d24096_0cudatoolkit anaconda/pkgs/main/linux-64::cudatoolkit-10.2.89-hfd86e86_1h5py anaconda/pkgs/main/linux-64::h5py-2.10.0-py38h7918eee_0libastra astra-toolbox/label/dev/linux-64::libastra-1.9.9.dev7-cuda_10.2_0libllvm9 anaconda/cloud/conda-forge/linux-64::libllvm9-9.0.1-he513fc3_1numpy-base anaconda/pkgs/main/linux-64::numpy-base-1.20.1-py38h7d8b39e_0pathtools anaconda/cloud/conda-forge/noarch::pathtools-0.1.2-py_1python_abi anaconda/cloud/conda-forge/linux-64::python_abi-3.8-2_cp38snappy anaconda/cloud/conda-forge/linux-64::snappy-1.1.8-he1b5a44_3The following packages will be UPDATED:ca-certificates pkgs/main::ca-certificates-2021.4.13-~ --> anaconda/cloud/conda-forge::ca-certificates-2021.5.30-ha878542_0certifi pkgs/main::certifi-2020.12.5-py38h06a~ --> anaconda/cloud/conda-forge::certifi-2021.5.30-py38h578d9bd_0conda pkgs/main::conda-4.10.1-py38h06a4308_1 --> anaconda/cloud/conda-forge::conda-4.10.3-py38h578d9bd_1openssl pkgs/main::openssl-1.1.1k-h27cfd23_0 --> anaconda/pkgs/main::openssl-1.1.1l-h7f8727e_0The following packages will be SUPERSEDED by a higher-priority channel:anaconda pkgs/main::anaconda-2021.05-py38_0 --> anaconda/pkgs/main::anaconda-custom-py38_1Proceed ([y]/n)?Downloading and Extracting Packages libllvm9-9.0.1 | 25.1 MB | ################################################################################################################################################################################################################################### | 100% astra-toolbox-1.9.9. | 432 KB | ################################################################################################################################################################################################################################### | 100% snappy-1.1.8 | 32 KB | ################################################################################################################################################################################################################################### | 100% cudatoolkit-10.2.89 | 365.1 MB | ################################################################################################################################################################################################################################### | 100% openssl-1.1.1l | 2.5 MB | ################################################################################################################################################################################################################################### | 100% anaconda-custom | 35 KB | ################################################################################################################################################################################################################################### | 100% h5py-2.10.0 | 1.1 MB | ################################################################################################################################################################################################################################### | 100% numpy-base-1.20.1 | 4.6 MB | ################################################################################################################################################################################################################################### | 100% _anaconda_depends-20 | 6 KB | ################################################################################################################################################################################################################################### | 100% pathtools-0.1.2 | 8 KB | ################################################################################################################################################################################################################################### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done (base)
安装完毕后
pip list |grep toolbox 命令可以查到安装的包
Anaconda3环境使用TensorFlow报错解决记录 mistGPU相关推荐
- kotlin Unresolved reference报错解决记录
遇到一个抓狂的问题就是项目转kotlin后一直报:Unresolved reference:XXXXXXX 项目预编译可以没报错,但一mark就报这个问题,问题所报位置都和项目中使用kotlin定义的 ...
- ajaxSubmit报错解决记录
ajaxSubmit提交js报错,需要在页面单独引入jquery.form.js <scripttype="text/JavaScript" src="${page ...
- Python 虚拟环境迁移路径后pip报错解决记录
为了保持不同项目之间包管理的独立,一般每个项目中都会独用一个虚拟环境venv,venv放在项目根目录下,在项目迁移的时候虚拟环境一般是不敢乱动的,容易报很多莫名其妙的错误,比如:因此,每次移动项目都是 ...
- keras和tensorflow 报错解决:UserWarning: Method on_batch_end() is slow compared to the batch update Check
早上在使用keras时报错如下: C:\Users\peter\Anaconda3\lib\site-packages\keras\callbacks.py:122: UserWarning: Met ...
- python3.7.4怎么运行_记一次win7在python3.7.4环境启动ride报错解决
配置: 系统:windows win7 python版本:3.7.4 robotframework-ride版本:1.7.4.1 问题: 双击快捷方式.双击ride.py文件都打不开ride界面 命令 ...
- 小程序app.json: app.json 未找到报错解决记录
在调试腾讯云的产品过程中遇到了这个问题,查了一通发现很多所谓的解决方法都不在根本上,特此记录下 首先,小程序必须要有app.json app.js app.wxss这三个主体,并且要放在根目录中, 在 ...
- IDEA Maven 多module项目导入 pom文件报错解决记录
具体描述: Non-resolvable parent POM: Could not find artifact 具体例子: root下的pom文件 <?xml ...
- Python3.5 win10环境下导入kera/tensorflow报错的解决方法
这篇文章主要介绍了Python3.5 win10环境下导入keras/tensorflow报错的解决方法,较为详细的分析了Python3.5在win10环境下导入keras/tensorflow提示错 ...
- 解决tensorflow报错:AttributeError: module ‘tensorflow.keras.backend‘ has no attribute ‘get_session‘ 问题
欢迎大家关注笔者,你的关注是我持续更博的最大动力 原创文章,转载告知,盗版必究 解决tensorflow报错:AttributeError: module 'tensorflow.keras.back ...
最新文章
- 仿京东首页上侧导航左侧地址栏布局(1)
- vue之filter用法
- 802d简明调试手册_SINUMERIK-828D简明调试手册.pdf
- mysql5.6semi plugin_mysql5.6 semi replication 半同步复制配置(示例代码)
- sqlserver 2008修改数据库表的时候错误提示“阻止保存要求重新创建表的更改”...
- python语言程序设计实践教程陈东_《Python程序设计》(陈春晖)【摘要 书评 试读】- 京东图书...
- 博客地址迁移www.xiangquba.cn
- JAVA读锁不使用效果一样_为什么Java的同步集合不使用读/写锁?
- linux命令iconv_Linux中iconv命令的简介和使用方法
- 锐捷校园网使用python登录
- BT种子文件信息库-TorrentinfoLibrary
- 手机号码正则表达式匹配
- FIR与IIR滤波器
- python for ArcGIS 绘制沈阳市板块地图
- 用博奥如何导入单项工程电子表_博奥工程系列软件实操手册第六册.doc
- 灰鸽子--木马、后门实验
- 内是不是半包围结构_如何区分半包围结构的字?
- 条码WMS系统与ERP接口实现方法
- i7 10510U性能怎么样?相当于台式机什么水平
- PyTorch聊天机器人(一)
热门文章
- 电脑蓝屏处理:WHEA_UNCORRECTABLE_ERROR
- 《我的眼睛--图灵识别》第一章:起源
- djnago+vue+element ui前后的分离上传图片并保存
- 企业做好战略管理要注意的五个关键点
- 使用正交测试法设计测试用例-完整总结
- 三国风云辅助工具——乌鸦的机器人
- 【Java EE】-JVM
- python做gui好吗_使用Python制作一个铅笔类(Python GUI编程)
- 百无聊赖之JavaEE从入门到放弃(二)基础语法
- SQL Server要求查询所有姓‘’王‘’的员工信息