第三周的课程是目标检测
,编程作业是以yolo网络为主。编程作业的主要部分是对yolo网络输出进行
anchor boxes过滤、IOU过滤、非极大抑制处理。
理论知识
交并比(Intersection-over-Union,IoU),目标检测中使用的一个概念,是产生的候选框(candidate bound)与原标记框(ground truth bound)的交叠率,即它们的交集与并集的比值。IOU值越大,说明得到的候选框越准确,最理想情况是完全重叠,即比值为1。
IOU
anchor boxes
anchor boxes(候选区域)
非极大抑制
非极大抑制,在检测的时候可能存在重叠的备选框,对于非极大可能性的被选框进行抛弃。
如果是多目标检测,就进行多次非极大抑制。
从算法中可以看到,做了两步discard:
第一步是对Pc <=0.6 的格子进行discard
第二步是对剩下的格子中,重叠区域 IOU>0.5 的进行非极大discard
程序
pycharm版
原本编程作业是 jupyter notebook ,但是环境没配好,所以这里使用pycharm将程序进行整合、调试。
import argparse
import os
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
import scipy.io
import scipy.misc
import numpy as np
import pandas as pd
import PIL
import tensorflow as tf
from keras import backend as K
from keras.layers import Input, Lambda, Conv2D
from keras.models import load_model, Model
from yolo_utils import read_classes, read_anchors, generate_colors, preprocess_image, draw_boxes, scale_boxes
from yad2k.models.keras_yolo import yolo_head, yolo_boxes_to_corners, preprocess_true_boxes, yolo_loss, yolo_body
from keras.utils import plot_model
def yolo_filter_boxes(box_confidence, boxes, box_class_probs, threshold=.6):
"""Filters YOLO boxes by thresholding on object and class confidence.
Arguments:
box_confidence -- tensor of shape (19, 19, 5, 1)
boxes -- tensor of shape (19, 19, 5, 4)
box_class_probs -- tensor of shape (19, 19, 5, 80)
threshold -- real value, if [ highest class probability score < threshold], then get rid of the corresponding box
Returns:
scores -- tensor of shape (None,), containing the class probability score for selected boxes
boxes -- tensor of shape (None, 4), containing (b_x, b_y, b_h, b_w) coo