资源简介
caffe ssd 深度学习 目标检测 python代码,包括单线程和多线程,使用摄像头作为输入视频源。
代码片段和文件信息
# coding: utf-8
# # Detection with SSD
#
# In this example we will load a SSD model and use it to detect objects.
# ### 1. Setup
#
# * First Load necessary libs and set up caffe and caffe_root
# In[1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import skimage.io
import time
plt.rcParams[‘figure.figsize‘] = (10 10)
plt.rcParams[‘image.interpolation‘] = ‘nearest‘
plt.rcParams[‘image.cmap‘] = ‘gray‘
# Make sure that caffe is on the python path:
caffe_root = ‘/ssda/software/caffe/‘ # this file is expected to be in {caffe_root}/examples
import os
os.chdir(caffe_root)
import sys
sys.path.insert(0 ‘python‘)
import getopt
import caffe
caffe.set_device(0)
caffe.set_mode_gpu()
# The device id for webcam
webcam_id = 0
# Number of frames to be skipped.
skip_frames = 0
# * Load LabelMap.
# In[2]:
from google.protobuf import text_format
from caffe.proto import caffe_pb2
# load PASCAL VOC labels
labelmap_file = caffe_root + ‘/data/VOC2012_SMALL/labelmap_voc.prototxt‘
file = open(labelmap_file ‘r‘)
labelmap = caffe_pb2.LabelMap()
text_format.Merge(str(file.read()) labelmap)
def get_labelname(labelmap labels):
num_labels = len(labelmap.item)
labelnames = []
if type(labels) is not list:
labels = [labels]
for label in labels:
found = False
for i in xrange(0 num_labels):
if label == labelmap.item[i].label:
found = True
labelnames.append(labelmap.item[i].display_name)
break
assert found == True
return labelnames
# * Load the net in the test phase for inference and configure input preprocessing.
# In[3]:
model_def = ‘models/VGGNet/VOC2012_SMALL/SSD_300x300/deploy.prototxt‘
model_weights = ‘models/VGGNet/VOC2012_SMALL/SSD_300x300/VOC2012_SMALL_SSD_300x300_iter_40000.caffemodel‘
net = caffe.Net(
model_def # defines the structure of the model
model_weights # contains the trained weights
caffe.TEST) # use test mode (e.g. don‘t perform dropout)
# input preprocessing: ‘data‘ is the name of the input blob == net.inputs[0]
transformer = caffe.io.Transformer({‘data‘: net.blobs[‘data‘].data.shape})
transformer.set_transpose(‘data‘ (2 0 1))
transformer.set_mean(‘data‘ np.array([104 117 123])) # mean pixel
transformer.set_raw_scale(
‘data‘ 255
) # the reference model operates on images in [0255] range instead of [01]
transformer.set_channel_swap(
‘data‘
(2 1 0)) # the reference model has channels in BGR order instead of RGB
#
#
# ### 2. SSD detection
# * Load an image.
# In[4]:
# set net to batch size of 1
image_resize = 300
net.blobs[‘data‘].reshape(1 3 image_resize image_resize)
# by ASUKA
global num
num = 0
def detect(image1):
# 传进来的image1的dtype为uint8
# print image1.shape
# print image1.dtype
# print image1.size
# image = np.array(image1 dtype=np.float32)
# image = caffe.io.resize_image(image1 (480 640))
image = skimage.img_as_float(i
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9221 2017-07-04 20:23 ssd_vid_voc2012_small_multthread.py
文件 7255 2017-07-03 17:00 ssd_vid_voc2012_small.py
----------- --------- ---------- ----- ----
16476 2
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论