热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

darknet的实现

一、下载与安装下载网络与权重文件:点击打开链接darkflow实现了将darknet翻译成tensorflow,可以用tensorflow加载darknet训练好

一、下载与安装

下载网络与权重文件:点击打开链接

darkflow实现了将darknet翻译成tensorflow,可以用tensorflow加载darknet训练好的模型,并使用tensorflow重新训练,输出tensorflow graph模型,用于移动设备。dark flow需要安装的依赖库有numpy,tensorflow,opencv,python等。

打开下载好的文件夹,里面有如下文件:

[{'label': 'bear', 'confidence': 0.33084026, 'topleft': {'x': 186, 'y': 29}, 'bottomright': {'x': 426, 'y': 380}}, {'label': 'dog', 'confidence': 0.56702411, 'topleft': {'x': 192, 'y': 58}, 'bottomright': {'x': 418, 'y': 374}}]

可以看出,结果还是比较准确的。

2.2 视频的测试

视频也是同样的,放在同一文件夹下,将图片换成视频,一帧一帧的处理。

import cv2
import numpy as np
from darkflow.net.build import TFNet
import matplotlib.pyplot as pltoption = {'model': 'D:\Python\darkflow-master\cfg\yolo.cfg', 'load': 'D:/Python/darkflow-master/bin/yolov2.weights','thereshold': 0.15}
tfnet = TFNet(option)
cap = cv2.VideoCapture("D:/Python/darkflow-master/test.mp4")
fps = 30
size = (1920, 1080)
writer = cv2.VideoWriter('dark.avi', -1, fps, size)
colors = [tuple(255 * np.random.rand(3)) for i in range(5)]
while (cap.isOpened()):ret, frame = cap.read()results = tfnet.return_predict(frame)if ret:for color, result in zip(colors, results):tl = (result['topleft']['x'], result['topleft']['y'])br = (result['bottomright']['x'], result['bottomright']['y'])label = result['label']cv2.rectangle(frame, tl, br, color, 7, )cv2.putText(frame, label, tl, cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)writer.write(frame)cv2.imshow('frame',frame)if cv2.waitKey(1) & 0xFF == ord('q'):breakelse:cap.release()cv2.destroyAllWindows()break

由于不能上传视频,只能截取其中一部分图片了


处理的结果如图:

2.3  darkflow的配置文件

打开cfg文件下的yolo.cfg文件,可以看到网络的构架如下:

[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=8
width=608
height=608
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky

[convolutional]

batch_normalize=1

filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky

[convolutional]

batch_normalize=1

filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[route]
layers=-9
[convolutional]
batch_normalize=1
size=1
stride=1
pad=1
filters=64
activation=leaky
[reorg]
stride=2
[route]
layers=-1,-4
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=425
activation=linear
[region]
anchors =  0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
bias_match=1
classes=80
coords=4
num=5
softmax=1
jitter=.3
rescore=1
object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1
absolute=1
thresh = .1

random=1

以上就是关于dark flow的全部内容,更多详细内容见官网:点击打开链接


推荐阅读
author-avatar
Cika_用假名说真话
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有