对同一操作系统上的不同版本的Tensorflow感到困惑

时间:2020-09-14 08:13:28

标签: python tensorflow deep-learning version

我需要运行一些使用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版本。那么,如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

Tensorflow不喜欢在同一环境中安装和卸载beeing,这可能会引起类似您所遇到的问题。

我总是建议使用诸如anaconda之类的环境工具来管理您的环境,并根据您的情况设置tro环境,其中一个用于tf2.0,另一个用于tf1.14。这样,您将始终拥有一个可以独立完成其工作的工作环境。

我还写了一个关于该主题的博客article,对您来说可能很有趣。