深度学习实践——三步轻松用YOLO实现目标识别

in #cn-stem5 years ago

上一篇文章介绍了YOLO和目标识别算法,大家是不是迫不及待跃跃欲试了。先不要着急,YOLO本身原理虽然简单,但是实现起来也不容易。YOLO原生是用C语言写的,放在无法直接用Python实现。

当然我们完全可以根据其原理搭建一个YOLO模型,但是对于初学者而言,完全没有必要再发明轮子嘛。github上的大神们已经用各种流行的框架实现了YOLO,今天我们就来介绍一个通过Keras实现YOLO的项目。通过这个项目,我们只需要三步,就能实现视频和图片的目标识别。

项目地址在这里

https://github.com/qqwweee/keras-yolo3

1. 官网下载YOLO模型参数

当然,你可以自己训练模型的参数,但是普通人恐怕没这个硬件条件,我们只是想体验一下YOLO的识别效果嘛,模型参数直接去YOLO官网下载就好了。

首先git clone 整个项目,不会git的朋友可以直接下载zip压缩包,当然打开终端cd到项目根目录,命令行一键可下载模型参数

wget https://pjreddie.com/media/files/yolov3.weights

2. 模型参数转换

注意模型参数权重和模型参数的配置文件一定要匹配,项目中已经有两个配置文件yolov3.cfg和yolov3-tiny.cfg,所以只需要下载对应的权重文件就可以了。YOLO官网也提供了配置文件和相应的参数权重。

运行项目文件下的convert.py完成参数转换,将模型转换成Keras的h5文件。

python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5

3. 模型使用

使用模型仅需要运行yolo_video.py这个文件就可以了。识别图片仅需要运行这一行命令

python yolo_video.py --image

终端会提示输入图片文件的filename

Input image filename:

将你要检测的图片文件放在项目文件夹下,输入文件名,目标识别就开始啦。

我们找一张图片试试效果吧

image-20190412161543361

image source from unsplash by Chander Mohan

当然也可以对视频文件进行目标识别,由于我的笔记本运行起来比较慢,这里就不做演示了,yolo_video.py的使用说明如下

usage: yolo_video.py [-h] [--model MODEL] [--anchors ANCHORS]
                     [--classes CLASSES] [--gpu_num GPU_NUM] [--image]
                     [--input] [--output]

positional arguments:
  --input        Video input path
  --output       Video output path

optional arguments:
  -h, --help         show this help message and exit
  --model MODEL      path to model weight file, default model_data/yolo.h5
  --anchors ANCHORS  path to anchor definitions, default
                     model_data/yolo_anchors.txt
  --classes CLASSES  path to class definitions, default
                     model_data/coco_classes.txt
  --gpu_num GPU_NUM  Number of GPU to use, default 1
  --image            Image detection mode, will ignore all positional 

code from github with MIT License

尾巴

简单三步我们在自己的电脑上就实现了YOLO模型,感兴趣的朋友可以去项目地址下载并阅读源代码。


相关文章

AI学习笔记——精准识别You Only Look Once(YOLO)

Tensorflow入门——单层神经网络识别MNIST手写数字

Tensorflow入门——多层神经网络MNIST手写数字识别

AI学习笔记——Tensorflow中的Optimizer

Tensorflow入门——分类问题cross_entropy的选择

AI学习笔记——Tensorflow入门

Tensorflow入门——Keras简介和上手



同步到我的简书

https://www.jianshu.com/u/bd506afc6fc1

Sort:  

你今天过的开心吗?想要参加活动但是不知道从何开始?关注寻宝团@cn-activity每日整理社区活动!如果不想再收到我的留言,请回复“取消”。

Congratulations @hongtao! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published more than 100 posts. Your next target is to reach 150 posts.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

You can upvote this notification to help all Steem users. Learn how here!



This post has been voted on by the SteemSTEM curation team and voting trail. It is elligible for support from @curie.

If you appreciate the work we are doing, then consider supporting our witness stem.witness. Additional witness support to the curie witness would be appreciated as well.

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Please consider setting @steemstem as a beneficiary to your post to get a stronger support.

Please consider using the steemstem.io app to get a stronger support.

Coin Marketplace

STEEM 0.31
TRX 0.12
JST 0.033
BTC 64605.91
ETH 3159.61
USDT 1.00
SBD 4.11