Ubuntu中conda下配置tensorflow2.0.0
1:安装anaconda,并创建一个tf的虚拟环境
conda create -n tf python=2.7
因为ros是基于python2.7,所以使环境python=2.7
激活该环境:conda activate tf
退出该环境:conda deactivate
删除该虚拟环境:conda remove -n tf --all
2:安装opencv
sudo apt-get install ros-kinetic-vision-opencv libopencv-dev python-opencv
3:在清华源下安装tensorflow2.0.0
pip install pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple //使用清华镜像安装
4:不同的版本的tensorflow会出现某些module调用不一样,例如
'module' object has no attribute 'ConfigProto'
可以百度,改代码,使之在对应的tensorflow下。
#原版 config = tf.ConfigProto(allow_soft_placement=True)
config = tf.compat.v1.ConfigProto(allow_soft_placement=True)
#原版 sess = tf.Session(config=config)
sess =tf.compat.v1.Session(config=config) #注意 ,这里为tensorflow2.0版本,与第1.0有差距。
当然,也可以尝试安装tensorflow1.0的版本。