主要是由于代码是基于tensorflow1.0编写的,目前最新的版本是2.0,版本更新比较大,很多方法已经改名,或者弃用。多数报错为 has no attribute 'xxx'
为确保高版本的TF支持低版本的TF代码,升级脚本加入了 compat.v1 模块。
此模块将以等效的 tf.compat.v1.foo 引用代替表单 tf.foo 的调用。
不过,建议您手动检查此类替代方案,并尽快将其迁移至 tf.* 命名空间(代替 tf.compat.v1.* 命名空间)中的新 API。
还有一些其他模块,新的版本中方法名有所变动
File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/util.py", line 5, in
from skimage.measure import compare_ssim as ssim
模块已经改名
修改/home/mist/1DeepAdverserialRegulariser/ClassFiles/util.py
改为
from skimage.metrics import structural_similarity as ssim
Traceback (most recent call last):
File "Adversarial_Regulariser.py", line 3, in
from ClassFiles.data_pips import LUNA
File "/home/mist/1DeepAdverserialRegulariser/ClassFiles/data_pips.py", line 7, in
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)))
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
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()
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
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()
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
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)
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)
Traceback (most recent call last):
File "Adversarial_Regulariser.py", line 37, in
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
猴子补丁:
如图下所示:
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
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
如图下所示
使用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.1 latest version: 4.10.3 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/mist/anaconda3 added / updated specs: - astra-toolbox The following packages will be downloaded: package | build ---------------------------|----------------- _anaconda_depends-2020.07 | py38_0 6 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main anaconda-custom | py38_1 35 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main astra-toolbox-1.9.9.dev7 | py38h9d24096_0 432 KB astra-toolbox/label/dev cudatoolkit-10.2.89 | hfd86e86_1 365.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main h5py-2.10.0 | py38h7918eee_0 1.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main libllvm9-9.0.1 | he513fc3_1 25.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge numpy-base-1.20.1 | py38h7d8b39e_0 4.6 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main openssl-1.1.1l | h7f8727e_0 2.5 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main pathtools-0.1.2 | py_1 8 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge snappy-1.1.8 | he1b5a44_3 32 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge ------------------------------------------------------------ Total: 398.8 MB The following NEW packages will be INSTALLED: _anaconda_depends anaconda/pkgs/main/linux-64::_anaconda_depends-2020.07-py38_0 astra-toolbox astra-toolbox/label/dev/linux-64::astra-toolbox-1.9.9.dev7-py38h9d24096_0 cudatoolkit anaconda/pkgs/main/linux-64::cudatoolkit-10.2.89-hfd86e86_1 h5py anaconda/pkgs/main/linux-64::h5py-2.10.0-py38h7918eee_0 libastra astra-toolbox/label/dev/linux-64::libastra-1.9.9.dev7-cuda_10.2_0 libllvm9 anaconda/cloud/conda-forge/linux-64::libllvm9-9.0.1-he513fc3_1 numpy-base anaconda/pkgs/main/linux-64::numpy-base-1.20.1-py38h7d8b39e_0 pathtools anaconda/cloud/conda-forge/noarch::pathtools-0.1.2-py_1 python_abi anaconda/cloud/conda-forge/linux-64::python_abi-3.8-2_cp38 snappy anaconda/cloud/conda-forge/linux-64::snappy-1.1.8-he1b5a44_3 The following packages will be UPDATED: ca-certificates pkgs/main::ca-certificates-2021.4.13-~ --> anaconda/cloud/conda-forge::ca-certificates-2021.5.30-ha878542_0 certifi pkgs/main::certifi-2020.12.5-py38h06a~ --> anaconda/cloud/conda-forge::certifi-2021.5.30-py38h578d9bd_0 conda pkgs/main::conda-4.10.1-py38h06a4308_1 --> anaconda/cloud/conda-forge::conda-4.10.3-py38h578d9bd_1 openssl pkgs/main::openssl-1.1.1k-h27cfd23_0 --> anaconda/pkgs/main::openssl-1.1.1l-h7f8727e_0 The following packages will be SUPERSEDED by a higher-priority channel: anaconda pkgs/main::anaconda-2021.05-py38_0 --> anaconda/pkgs/main::anaconda-custom-py38_1 Proceed ([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 命令可以查到安装的包