GithubHelp home page GithubHelp logo

lesliezhoa / tensorflow-yolo1 Goto Github PK

View Code? Open in Web Editor NEW
135.0 10.0 47.0 2.27 MB

目标检测yolo算法,采用tensorflow框架编写,中文注释完全,含测试和训练,支持摄像头

Python 100.00%
yolo tensorflow chinese

tensorflow-yolo1's Introduction

tensorflow-YOLO1

目标检测yolo算法,采用tensorflow框架编写,中文注释完全,含测试和训练,支持摄像头

模型简介

yolo v1

yolo1是端对端的目标检测模型,参考论文为You Only Look Once:Unified, Real-Time Object Detection
主要**是将图片分割成cell_size * cell_size的格子,每个格子里只包含一个目标,通过网络来输出每个格子的目标值,其中判断格子中是否有目标即判断目标中心点是否在对应格子中。
模型大致结构图如下:

模型经过多层卷积和全连接层,将图片最终输出尺寸为[batch,cell_size * cell_size * (num_classes+ box_per_cell* 5)]。
简单介绍一下输出的表示:
通过reshape分成[batch,cell_size,cell_size,num_classes]表示每个格子对应的类别;

[batch_,cell_size,cell_size,box_per_cell]表示每个格子中是否存在目标的置信度,之所以选择两个box_per_cell是为了让预测精度更准确,通俗来讲就是三个臭皮匠顶一个诸葛亮;

[batch,cell_size,cell_size,box_per_cell,4]表示每个格子每个选框中的目标框的坐标值,4个值分别为目标图片的中心横纵坐标偏移值x,y,目标图片的长宽w,h,但都经过一定归一化处理。x,y是相对于格子的偏移量经过了除以整个图片大小的归一化。

举例说明:

就是原图目标的中心坐标是x1,y1,原图宽高分别为w1,h1假设目标中心坐落在下标为[0,1]的格子里,即int(x1/image_size* cell_size),int(y1/image_size* cell_size)=0,1,此时对应格子的目标置信度应该都为1,x和y应该是相对于[0,1]这个格子的偏移量,具体算法是:x=x1/image_size* cell_size-0,y=y1/image_size* cell_size-1。

w,h也进行归一化但还要开方,具体算法为:w=square(w1/image_size),h=square(h1/image_size),归一化可以把数值指定在一定范围有利于训练,把w,h开方,是因为w,h的值不同于x,y是格子的偏移量限定于一定区间,w,h是针对整个图片而言,变化没那么平缓,所以进行开方。

真实训练数据也按上述方法来处理,只不过刚开始的shape是[cell_size,cell_size,4]然后将它reshape成[cell_size,cell_size,1,4]再复制成[batch,cell_size,cell_size,box_per_cell,4]

关于损失函数计算有目标损失,无目标损失,类别损失,目标框损失,占比不同,实际显示图片要加上非极大值抑制,把两个很相近的目标框只保留置信度高的。

yolo v2

关于yolo v2 网上博客大致内容介绍很详细,可以参考论文YOLO9000: Better, Faster, Stronger
我主要介绍它的训练数据长什么样,这也是困扰我好久的。yolo v2 加了anchor box为上述每个格子提供多个目标的可能,真实值的目标要与anchor box计算iou值,大于阈值才保留,否则保留iou值最大的目标,这样label的shape就变成了[batch, cell_size, cell_size, N_ANCHORS, num_clsses+5],相关坐标x,y,w,h和yolo1处理方式也些许不同,感兴趣的同学可以去参考论文。

代码介绍

代码只针对于yolo1的训练和测试

环境说明:

主要环境配置为:
ubuntu 16.04
python 3.5.5
tensorflow 1.4.1
opencv 3.4.1
不知道windows可不可以,应该没问题

下载数据

训练数据下载VOC解压放置到data目录下,预训练模型放置到data目录下

代码介绍

data下放置训练数据和预训练模型和将数据生成的tfrecords文件
graph保存训练过程中的训练集和验证集的graph
model保存训练的最优model
output是测试图片保存目录
picture是测试图片放置目录
utils包括配置文件config,模型文件model,数据处理文件psscal_voc
image_test.py是判断生成tfrecords文件是否图片标注正确
test.py是测试文件
tfrecord.py是将数据处理成tfrecords格式
train.py是训练文件

运行

首先可以手动修改config配置文件
若要训练的话:
运行python tfrecord.py 生成数据
运行python train.py 训练数据

若要测试:
把自己喜欢图片放到picture内,本代码图片来源于百度图片
查看代码,确定你进行测试要使用的model,运行test.py
本测试代码支持摄像头

建议

建议下载预训练模型训练,训练次数不宜过长,否则过拟合很严重
本代码只保存验证集上的最优模型
代码参考hizhangp
如有错误还请多多指正

结果展示




tensorflow-yolo1's People

Contributors

lesliezhoa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tensorflow-yolo1's Issues

关于训练数据Label的问题

训练数据label的shape是[None, self.cell_size, self.cell_size, 5 + self.num_classes]),对于一个Cell中有一个目标时我知道这个label如何设置,但如果一个Cell中有多个目标或者没有目标的时候label该如何设置?谢谢!

train运行出错

你好,已经解决了这个问题,现在是另外一个问题,在pycharm下运行train.py完成后,
报告Process finished with exit code 0,输出一张result analysis 图,然后我又运行test.py,此时的config中的model_type='2'(用自己训练的模型)报错Process finished with exit code 1,我在model文件夹下看了一下,没有保存下最后训练的模型,请问哪里出了问题;model_type='1'时用预训练模型结果正常

关于label生成的一点问题

您好,非常感谢您提供这么好的资源
在学习这方面内容的时候,对于label的转换有一些疑问:
图像的标注数据为xml提供的坐标和类别数据
然而网络的输出是7730的张量,label则也是如此形式的张量
我的问题是这个转换过程是如何执行的呢?

配置文件Config.py文件里面的decay_step?

配置文件中的decay_step = 30000 似乎在代码里面没有用过,虽然我知道它是用来指定学习率衰减的迭代轮数,decay_steps是你想要每迭代多少轮就衰减的度量值,
但是为什么作者你没有用到这个参数呢??

单目标检测的问题?

您好!我把网络结构改成识别单个目标,虽然训练时训练集和验证集损失都很小,但是拿单个图片测试发现效果很差,而且测试不同图片生成的框位置几乎都是一样的。。想请您指点一下。。

train.py error

WARNING:tensorflow:From train.py:72: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

Traceback (most recent call last):
File "/home/kky/.local/lib/python3.8/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
File "/home/kky/.local/lib/python3.8/site-packages/tensorflow_core/python/client/session.py", line 1349, in _run_fn
return self._call_tf_sessionrun(options, feed_dict, fetch_list,
File "/home/kky/.local/lib/python3.8/site-packages/tensorflow_core/python/client/session.py", line 1441, in _call_tf_sessionrun
return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.OutOfRangeError: RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)
[[{{node shuffle_batch}}]]

我已经设置
batch_size=1
epoch=1
看样子没有可调整的空间,能否提供一些思路,谢谢!

About YOLO_small.cpkt

I have not download the YOLO_small.cpkt.After i trained the network,it detect nothing.Is that means i must use YOLO_small.cpkt for training?

预训练模型的问题?

    你好,我想询问一下你百度网盘提供的这个预训练模型,YOLO_small.ckpt,是你自己训练的吗?因为YOLO先使用ImageNet数据集对前20层卷积网络进行预训练,然后使用完整的网络,在PASCAL VOC数据集上进行完整网络的训练。
    但是官方提供的了一个预训练的权重文件,yolo.weights,然后我想问的问题是,你的预训练文件和官方提供的这个yolo.weights有什么区别,还是直接用yolo.weights转换成 .ckpt 的??

机器配置问题

请问我可以用GTX1650 4G 8G运行内存的笔记本运行该程序吗,为什么我设置成GPU运行在训练的刚开始的时候就会导致运行内存很快达到8G然后进程被自动结束?

train.py出错

OutOfRangeError (see above for traceback): RandomShuffleQueue '_2_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 16, current size 1)
[[Node: shuffle_batch = QueueDequeueManyV2[component_types=[DT_FLOAT, DT_DOUBLE], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/device:CPU:0"](shuffle_batch/random_shuffle_queue, shuffle_batch/n)]]

Where is the given pre-trained model, i.e. the checkpoint?

Hello,
I want to use the given code for test only (no train), using a pre trained model.
Where is the checkpoint located?
I can't find it in your code.
In general, in the most of the folders (data,graph,model) I see just readme files.
Thanks!

运行train.py时出错

tensorflow.python.framework.errors_impl.InternalError: Dst tensor is not initialized.
[[Node: yolo/conv_20/weights/_267 = _Recv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_26_yolo/conv_20/weights", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](^_arg_save/Const_0_0, ^save/SaveV2/tensor_names, ^save/SaveV2/shape_and_slices)]]

train中断后如何恢复

我在服务器上运行train。py 但是之后断开了连接,再次进入的时候又需要重新训练,请问如何能够从上次的断点继续训练呢?完整训练一次大概需要多长时间呢?

jupyter上运行出错

我把test.py内容放到jupyter上,在运行时会自己中断,这是什么原因?
我的系统是服务器版的,然后在docker中运行的,是不是没有安装界面环境的原因啊?

提示错误

这个程序是否经过验证,有些小问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.