关于在百度AI studio中使用TensorFlow

目录

可在百度AI studio的终端(相当于cmd)中安装TensorFlow

但是在项目中的NoteBook中,无法使用TensorFlow

经网上查阅资料后,得知可在AI studio的终端中使用TensorFlow

另,百度AI Studio确可提供运算服务

综上,百度AI Studio确可提供运算服务,且相当于免费。但若要在其上使用TensorFlow,则需费些功夫,更具体的使用效果有待进一步实验验证

 

 

 

 

可在百度AI studio的终端(相当于cmd)中安装TensorFlow:

过程如下图所示:

关于在百度AI studio中使用TensorFlow_第1张图片

 

 

但是在项目中的NoteBook中,无法使用TensorFlow。

如下图所示:

首先,NoteBook示例:

关于在百度AI studio中使用TensorFlow_第2张图片

新建cell,输入以下代码:

import tensorflow as tf
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"]='3'
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

运行后,报错:

意为本平台中已有一套完整的框架,即为PaddlePaddle(飞桨),无法再使用TensorFlow。

 

经网上查阅资料后,得知可在AI studio的终端中使用TensorFlow,方法如下:

先在终端中安装miniconda3,

下载:
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.7.12.1-Linux-x86_64.sh
安装:
bash Miniconda3-4.7.12.1-Linux-x86_64.sh

激活conda:
source ~/miniconda3/bin/avtivate

更换清华源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 
conda config --set show_channel_urls yes

激活conda
source ~/miniconda3/bin/activate

创建环境
conda create --name Env_PyTorch python=3.7

进入创建好的环境
conda activate Env_Pytoch

然后安装TensorFlow:

pip install tensorflow==1.15.0

再在终端中输入python,进入python,输入如下代码:

import tensorflow as tf
sess = tf.Session()
a = tf.constant(2)
b = tf.constant(3)
print(sess.run(a+b))

此时,在分别输入每一条语句时,会出现一些可能是底层信息,并无大碍。

运行结果如下:

关于在百度AI studio中使用TensorFlow_第3张图片

证明可使用TensorFlow。

 

另,百度AI Studio确可提供运算服务,例如:

之前使用随机梯度下降算法进行迭代优化,在本地电脑上无法完成,因为耗时太大,但其实数据集并不是很多。

但放在百度AI Studio上,则可快速运行出结果。

关于在百度AI studio中使用TensorFlow_第4张图片

 

 

综上,百度AI Studio确可提供运算服务,且相当于免费。但若要在其上使用TensorFlow,则需费些功夫,更具体的使用效果有待进一步实验验证。

你可能感兴趣的:(关于在百度AI studio中使用TensorFlow)