如何在 2.0 和 1.x 之间切换 tensorflow 版本? [英] How switch tensorflow versions between 2.0 and 1.x?

查看:22
本文介绍了如何在 2.0 和 1.x 之间切换 tensorflow 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法切换 tensorflow 的版本?,当我使用 conda 安装 tensorflow 2.0 时,它甚至更新了很多东西,甚至是 python.在运行 conda list 时,它会显示两个版本;

Is there a way to switch versions of tensorflow?, when I installed tensorflow 2.0 using conda, it updated many things even python. On runing conda list it shows both versions;

张量流 2.0.0 mkl_py37h66b46cc_0
张量流 1.13.1 <点>

tensorflow 2.0.0 mkl_py37h66b46cc_0
tensorflow 1.13.1 < pip>

为了使用 1.x 版本,建议在此处替换 import tensorflow astf 用于以下内容:

import tensorflow.compat.v1 as tftf.disable_v2_behavior()

使用这个方法是安全的,只是添加这些行?,在我的例子中它显示一个警告:

警告:tensorflow:来自/home/common/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/compat/v2_compat.py:65:disable_resource_variables(来自tensorflow.python.ops.variable_scope)已弃用,将被弃用在以后的版本中删除.更新说明:长期不支持非资源变量

In order to use the 1.x version it's recommended here to replace import tensorflow as tf for the following :

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

It is safe to use this method, just adding these lines?, in my case it shows a warning:

WARNING:tensorflow:From /home/common/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term

推荐答案

我个人会在这里使用两个不同的虚拟环境.这将确保您在使用 2.0 与 1.x 时没有依赖性问题.Conda 环境非常易于使用.例如:

I would personally use two different virtual environments here. This would make sure you don't have dependency issues when using 2.0 vs 1.x. Conda environments are very easy to use. For example:

创建环境

conda create --tensorflow1

激活环境

conda activate tensorflow1

激活环境后,您可以通过 conda/pip 安装 TensorFlow 1.x,所有依赖项都将包含在环境中.你可以用 TensorFlow 2.0 做同样的事情.

When you have the environment activated you can conda/pip install TensorFlow 1.x and all dependencies will be contained within the environment. You can do the same thing with TensorFlow 2.0.

我无法对您发布的上述解决方案发表评论,但在这些情况下,虚拟环境非常有用.

I can't comment on the above solution you have posted, but these are the cases where virtual environments are extremely useful.

此处提供完整文档:

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

这篇关于如何在 2.0 和 1.x 之间切换 tensorflow 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆