SSD目标检测

来源:互联网 发布:甲骨文软件开发 编辑:程序博客网 时间:2024/05/22 01:43

SSD目标检测

SSD是继yolo又一神作,对其理论这边就不介绍了,给上链接:
http://blog.csdn.net/u011534057/article/details/52733686

这边只讲代码编译,最近想试一下SSD的速度,看看在CPU端每秒能够检测几张图。原本一直编译C++(CAFFE)版本的,但是C++小白遇到很多问题,在同事的帮助下还是未能解决。后就选择编译TF的SSD,https://github.com/balancap/SSD-Tensorflow
按照网上的教程,测试很简单,这边只是对其作了简单的修改,直观的了解速度:

用jupyter notebook 打开SSD-Tensorflow/notebooks/ssd_notebook.ipynb

将:

gpu_options = tf.GPUOptions(allow_growth=True)config = tf.ConfigProto(log_device_placement=False, gpu_options=gpu_options)isess = tf.InteractiveSession(config=config)

注释掉,修改成

isess = tf.InteractiveSession()

(这里测试只用CPU)

最后显示部分也进行了修改,不适用原有的显示方式,而是调用摄像头,代码如下:

def Imshow_img(img, classes, scores, bboxes):    height = img.shape[0]    width = img.shape[1]    for i in range(len(classes)):        cls_id = int(classes[i])        if cls_id >= 0:            score = scores[i]        ymin = int(bboxes[i, 0] * height)        xmin = int(bboxes[i, 1] * width)        ymax = int(bboxes[i, 2] * height)        xmax = int(bboxes[i, 3] * width)        cv2.rectangle(img,(xmin, ymin), (xmax, ymax), (55,255,155),5)        text  = [str(rclasses[i]) +'|'+ str(rscores[i])]        cv2.putText(img,  text[0], (xmin, ymin-2), cv2.FONT_HERSHEY_TRIPLEX, 1, (255, 0 ,0), thickness = 1, lineType = 1)
import cv2  import numpycap = cv2.VideoCapture(0)while(1):    # get a frame    ret, frame = cap.read()    rclasses, rscores, rbboxes =  process_image(frame)    Imshow_img(frame, rclasses, rscores, rbboxes)    # show a frame    cv2.imshow("capture", frame)    if cv2.waitKey(1) & 0xFF == ord('q'):        breakcap.release()cv2.destroyAllWindows() 

如果想显示时间,也可以加上测试时间显示。
SSD的目标检测时间目前还是无法在嵌入式端使用,Google最近发布的tensorflow object detection API,将SSD和MobileNet结合,效果应该比SSD+VGG的好,后面会测试一下。