最近在阅读《深度学习之TensorFlow:入门、原理与进阶实战》,实际操作上有点总结体会。
- 安装
书中使用的TensorFlow 是1.4, python 版本是3.5.0 ,anaconda 是anaconda3-4.1.1,安装教程也是Windows。而我是Mac,自带安装的python是3.7,所以需要做一些修改。
1. python官网下载python3.5.0 进行安装,不用直接使用anaconda的预设,直接使用anaconda预设会发现运行程序时报python 非 framework 安装。
2. 下载安装anaconda ,这里推荐一篇博客https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/,里面讲的是使用清华源进行安装。
3. 下载安装TensorFlow,安装时需要指定版本是1.4,要不然会安装最新版本。使用官方源站较慢,推荐使用阿里云的源,具体操作如下:
python3.5 -m pip install --index-url https://mirrors.aliyun.com/pypi/simple tensorflow==1.4.0
4. 建立执行环境,可以参考 https://www.jianshu.com/p/742dc4d8f4c5 ,里面讲的比较细致,还可以将anaconda下载库的源地址修改,关键代码是:
#更改anaconda库的下载源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes
#创建环境
conda create -n your_env_name python=3.5
#进入环境
source activate your_env_name
#退出环境
source deactivate your_env_name
5. 进入环境之后执行书中代码,若还是报确实TensorFlow,则再次执行下载TensorFlow的操作,即执行第三步。
目前亲测,可以正确执行里面的所有代码