我需要运行一些使用tensorflow版本低于2.0的代码(https://github.com/gnsrla12/crash_to_not_crash) (我不知道确切的版本是什么)。在我通过"pip3 install tensorflow==1.14“将tensorflow降级到1.14之前。当我通过pip3列出tensorflow的版本时,我有:
$ pip3 list | grep tensorflow
tensorflow 1.14.0
tensorflow-datasets 2.1.0
tensorflow-estimator 2.0.0
tensorflow-metadata 0.21.1
tensorflow-probability 0.11.0甚至当我运行以下代码行时:
$ python3 -c 'import tensorflow as tf; print(tf.__version__)'我有(我不关注由NumPy版本引起的FutureWarnings ):
1.14.0但是当我运行某个模块时:
$ python3 ./scripts/test_script.py它的内部是这样的:
import os, time, random, itertools
import tensorflow as tf
import numpy as np
from sklearn import metrics
from matplotlib import pyplot as plt
print("tf version is ", tf.__version__)
opt = TestOptions().parse()
opt.batchSize = 128
gpu_config = tf.ConfigProto(
device_count = {'GPU': opt.gpu_count}
)我明白了:
('tf version is ', '2.0.0')
Traceback (most recent call last):
File "test.py", line 18, in <module>
gpu_config = tf.ConfigProto(
AttributeError: 'module' object has no attribute 'ConfigProto'但是我想使用1.14版本,而不是2.0.0。那么,我该如何解决这个问题呢?
发布于 2020-09-14 17:39:00
Tensorflow不喜欢在同一个环境中安装和卸载,这可能会导致像您遇到的问题。
我总是推荐使用像anaconda这样的环境工具来管理您的环境,因此在您的情况下设置tro环境,一个用于tf2.0,一个用于tf1.14。这样,你就有了一个独立完成工作的工作环境。
我还写了一个关于这个话题的博客article,你可能会感兴趣。
https://stackoverflow.com/questions/63880499
复制相似问题