吴恩达深度学习-目标检测课后作业中使用的是tensorflow 1.X的版本,现在使用tf 2.x会出现各种报错问题,比较简单的方法是创建虚拟环境,然后安装tf 1.x运行代码
- 使用anaconda创建虚拟环境,并在jupyter notebook中运行代码
- 安装tensorflow和keras后,numpy和h5py这两个包的版本过高,在运行代码时会出现警告和错误,需要降级
- keras的版本过高也可能会有错误
tensorflow因numpy版本过高引起的警告:FutureWarning: Passing (type, 1) or ‘1type’ as a synonym of type is deprecated…
h5py版本太高引起报错: AttributeError: ‘str’ object has no attribute ‘decode’
在虚拟环境中安装指定版本的依赖库
# 创建并激活虚拟环境(yolov2_keras是虚拟环境名称)
conda create -n yolov2_keras
activate yolov2_keras
# 安装可以运行代码的各版本依赖库 (使用清华源安装)
pip install tensorflow==1.13.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install keras==2.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install numpy==1.16.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install h5py==2.10.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install imageio -i https://pypi.tuna.tsinghua.edu.cn/simple
#将虚拟环境添加到jupypter notebook的kernel中
python -m ipykernel install --name yolov2_keras
# 安装插件使jupyter支持虚拟环境
conda install nb_conda