环境很重要
YOLOv3用的都是低版本的。
使用Anaconda创建yolov3虚拟环境推荐以下版本:
安装keras
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple keras==2.1.5
安装tensorflow
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.12.0
安装Pillow
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pillow==7.2.0
安装matplotlib
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib
安装 ffmpeg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ffmpeg
安装opencv
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python==4.5.5.64
安装numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.16.0
安装h5py
pip install h5py==2.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
下载yolov3工程及权重文件
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==1.12.0
安装Pillow
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pillow==7.2.0
安装matplotlib
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib
安装 ffmpeg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ffmpeg
安装opencv
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python==4.5.5.64
安装numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.16.0
安装h5py
pip install h5py==2.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
下载yolov3工程及权重文件
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib
安装 ffmpeg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ffmpeg
安装opencv
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python==4.5.5.64
安装numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.16.0
安装h5py
pip install h5py==2.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
下载yolov3工程及权重文件
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python==4.5.5.64安装numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy==1.16.0安装h5py
pip install h5py==2.9.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
下载yolov3工程及权重文件
YOLOv3工程代码:https://github.com/qqwweee/keras-yolo3
权重文件:https://pjreddie.com/media/files/yolov3.weights
把权重文件放在keras-yolo3-master目录下
pycharm配置yolov3工程 把权重文件转换成h5文件
点击左下方的 Terminal (和IDLE一个功能,就是命令行),输入并回车等待:
python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5
最后会显示有句提示:Saved Keras model to model_data/yolo.h5
测试:方式一在工程目录下新建一个py程序,名字自拟如testYolov3,粘贴下面的代码:
from yolo3.model import yolo_body
from keras.layers import Input
from yolo import YOLO
from PIL import Image
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
yolo = YOLO()
while True:
img = 'img/0.jpg'
try:
image = Image.open(img)
except:
print('Open Error!')
continue
else:
rel_image = yolo.detect_image(image)
rel_image.show()
yolo.close_session()
再在工程目录下新建img文件夹,并放入一张照片,命名为0.jpg
运行 testYolov3程序:
至此yolov3配置完成
参考链接:https://blog.csdn.net/weixin_41967600/article/details/107753260
方式二在终端输入python yolo_video.py --image 之后输入图片路径即可如:img .jpg。



