资源简介
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试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论