ROS 20.04
Python3.7
TensorFlow2.8
使用祖码时发现了很多问题,归根结底也是版本的问题。
[En]
Many problems are found when using ancestral code, and in the final analysis, it is also the problem of the version.
Conda官方主页: https://github.com/conda/conda
我是x86_64 linux系统,所以下载 https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
conda的bin文件会添加到环境变量中,需要source一下
source ~/.bashrc
创建
conda create -n your_env_name python=3.7
linux
source activate your_env_name
#若返回系统原本环境,退出conda(或返回上一级环境)
conda deactivate
conda install -n your_env_name [package]
感谢:
因为contrib这个库不稳定,从而在高级一点的版本中删除了contrib这个库。
TensorFlow 2.0中提供了tensorflow.compat.v1代码包来兼容原有1.x的代码,可以做到几乎不加修改的运行。
import tensorflow as tf
替换成:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
TensorFlow 2.0中提供了命令行迁移工具,来自动的把1.x的代码转换为2.0的代码。工具使用方法如下(假设我们的程序文件名称为first-tf.py):
tf_upgrade_v2 --infile first-tf.py --outfile first-tf-v2.py
或者整个文件夹:
tf_upgrade_v2 --intree tf_pose --outtree tf_pose
问题1:No module named ‘_pafprocess’
解决办法:
$ cd ~/tf_pose/pafprocess/
$ swig -python -c++ pafprocess.i
$ python3 setup.py build_ext --inplace
问题2:ModuleNotFoundError: No module named ‘tensorflow.contrib’
问题部分:
import tensorflow.contrib.slim as slim
tensorflow2以上的版本没有contrib属性
解决办法:
pip install --upgrade tf_slim --user
将上述问题部分修改为:
[En]
Modify the above question section to:
import tf_slim as slim
问题3:AttributeError: module ‘tensorflow’ has no attribute ‘contrib’或者AttributeError: module ‘tensorflow’ has no attribute ‘layers’
问题部分:
_init_xavier = tf.contrib.layers.xavier_initializer()
解决办法:
将上述问题部分修改为:
[En]
Modify the above question section to:
_init_xavier = tf.truncated_normal_initializer(stddev=0.1)
问题4:AttributeError: module ‘tensorflow_core.compat.v1’ has no attribute ‘contrib’
问题部分:
_l2_regularizer_00004 = tf.contrib.layers.l2_regularizer(0.00004)
_l2_regularizer_convb = tf.contrib.layers.l2_regularizer(common.regularizer_conv)
TensorFlow删掉重复的接口,搭建网络则基本上复用了 Keras 的接口,即tf.keras
解决办法:
_l2_regularizer_00004 = tf.keras.regularizers.l2(0.00004)
_l2_regularizer_convb = tf.keras.regularizers.l2(common.regularizer_conv)
问题5:AttributeError: module ‘tensorflow’ has no attribute ‘slim’
问题部分:
slim = tf.slim
解决办法:
import tf_slim as slim
添加上述代码并删除问题部分
[En]
Add the above code and delete the problem section
问题6;RuntimeError: module compiled against API version 0xe but this version of numpy
解决办法:
pip3 install -U numpy
更新numpy版本
Original: https://blog.csdn.net/weixin_44362628/article/details/124627633
Author: Howe_xixi
Title: 【踩坑记录】tensorflow1.x 更新到 2.x 遇到的坑&&condad的基本使用方法
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/497404/
转载文章受原作者版权保护。转载请注明原作者出处!