资源简介
几个月前自己上手YOLOV3-keras,自己训练了一个数据集。在测试的时候,发现源码作者的测试不好用。自己稍稍修改了一下。
几点改进
(1)批量测试图片
将待测试的图片放入 './test'路径下。
测试的时候,第一张图片需要的时间大约是 2s左右,因为需要加载模型,所需时间就相对较长一些。在博主的机器上,测试一一张图片的时间大约是0.1s左右;
(2)保存测试结果
完成测试后,将测试的结果保存在result文件夹中。方便以后查看
(3)将测试结果输出为一个result.txt文件。
result.txt内容包含了每一个bbox的信息。
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Class definition of YOLO_v3 style detection model on image and video
“““
import colorsys
import os
from timeit import default_timer as timer
import time
import numpy as np
from keras import backend as K
from keras.models import load_model
from keras.layers import Input
from PIL import Image ImageFont ImageDraw
from yolo3.model import yolo_eval yolo_body tiny_yolo_body
from yolo3.utils import letterbox_image
from keras.utils import multi_gpu_model
path = ‘./test/‘ #待检测图片的位置
# 创建创建一个存储检测结果的dir
result_path = ‘./result‘
if not os.path.exists(result_path):
os.makedirs(result_path)
# result如果之前存放的有文件,全部清除
for i in os.listdir(result_path):
path_file = os.path.join(result_pathi)
if os.path.isfile(path_file):
os.remove(path_file)
#创建一个记录检测结果的文件
txt_path =result_path + ‘/result.txt‘
file = open(txt_path‘w‘)
class YOLO(object):
_defaults = {
“model_path“: ‘model_data/yolo.h5‘
“anchors_path“: ‘model_data/yolo_anchors.txt‘
“classes_path“: ‘model_data/coco_classes.txt‘
“score“ : 0.3
“iou“ : 0.45
“model_image_size“ : (416 416)
“gpu_num“ : 1
}
@classmethod
def get_defaults(cls n):
if n in cls._defaults:
return cls._defaults[n]
else:
return “Unrecognized attribute name ‘“ + n + “‘“
def __init__(self **kwargs):
self.__dict__.update(self._defaults) # set up default values
self.__dict__.update(kwargs) # and update with user overrides
self.class_names = self._get_class()
self.anchors = self._get_anchors()
self.sess = K.get_session()
self.boxes self.scores self.classes = self.generate()
def _get_class(self):
classes_path = os.path.expanduser(self.classes_path)
with open(classes_path) as f:
class_names = f.readlines()
class_names = [c.strip() for c in class_names]
return class_names
def _get_anchors(self):
anchors_path = os.path.expanduser(self.anchors_path)
with open(anchors_path) as f:
anchors = f.readline()
anchors = [float(x) for x in anchors.split(‘‘)]
return np.array(anchors).reshape(-1 2)
def generate(self):
model_path = os.path.expanduser(self.model_path)
assert model_path.endswith(‘.h5‘) ‘Keras model or weights must be a .h5 file.‘
# Load model or construct model and load weights.
num_anchors = len(self.anchors)
num_classes = len(self.class_names)
is_tiny_version = num_anchors==6 # default setting
try:
self.yolo_model = load_model(model_path compile=False)
except:
self.yolo_model = tiny_yolo_body(Input(shape=(NoneNone3)) num_anchors//2 num_classes) \
if is_tiny_version else yolo_body(Input(shape=(NoneNone3)) num_anchors//3 num_classes)
self.yolo_model.load_weights(self.model_path) # make sur
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8628 2019-04-15 18:12 yolo_test.py
文件 164 2019-04-15 19:35 readme.txt
相关资源
- 自动泊车效果测试-基于OPENCV与深度学
- glove6B
- 基于keras实现的LSTM网络
- 深度学习-PyTorch框架实战系列.rar
- 复数网络历史介绍.docx
- 2017年最新机器学习与深度学习从基础
- 深度学习框架Tensorflow学习与应用
- 2018斯坦福深度学习Tensorflow实战课程课
- halcon_17 深度学习
- 猫狗大战dogs_vs_cats)
- Siamese-RPN_code
- 深度玻尔兹曼机
- 神经网络和深度学习—吴恩达 第三周
- 深度学习 脑部图像分割
- 深度学习综述英文
- 基于tensorflow的猫狗图片的识别分类
- 吴恩达老师深度学习课程作业用到的
- word2vec 中的数学原理详解-电子版.do
- Human-level control through deep reinforcement
-
深度学习项目实战视频课程-st
yleT - FER2013数据集
- 基于深度学习的医学图像分割技术:
- 深度学习:深度压缩感知-从ISTA到LI
- 基于深度学习的人脸识别
- 基于深度学习的场景识别方法研究论
- 基于深度学习的智能识别APP云盘链接
- 分布式CNN代码
- 计算机视觉 从CV基础到深度学习实战
- FCN模型实现图像分割配套资料分享.
- 深度学习之TensorFlow 入门、原理与进阶
评论
共有 条评论