Caffe代码解读2--检测程序解读

在上一篇文章Caffe代码解读1--从一段命令行开始,我们说了如何训练一个神经网络,并以SSD网络为例,对用到的python脚本进行了分析。在这篇文章中,我们开始分析,如何使用神经网络进行目标检测,依旧是以SSD网络为例进行讲解。

打开控制台,输入两行命令:

cd  /home/**(您服务器的名字)/caffe
python examples/ssd/ssd_VOC0712/ssd_VOC0712_detect.py

我们打开这份python文件看一下

'''
Author: Mr.K

You can use this script detect one image, a group of images, a video file or the video strame from a camera.

If you choose to detect the image,
    After running this script, you will get images which you have choosen to detect and a detection result file.
    As for images, they are annotated with blue bounding box to show the objects that your network detected.
    As for the result file, its format is as followed:

    file_name: the/image/path/***.jpg
    para_name: xmin ymin xmax ymax label_id confidence label_name
    object:    **** **** **** **** ******** ********** **********
       .        .    .    .    .       .         .          .
       .        .    .    .    .       .         .          .
       .        .    .    .    .       .         .          .
    object:    **** **** **** **** ******** ********** **********

If you choose to detect a video or the video strame from a camera,
    After running this script, you will get a video file that has annotated with blue bounding box

compute speed without storing result,using VOC2007 dataset:
video:     58fps(forward), 18fps(loop)
one image: 36fps(forward), 19fps(loop)
images:    73fps(forward), 43fps(loop)

'''
import os
import os.path
import sys
import cv2
import time
import argparse
import numpy as np
# Make sure that caffe is on the python path:
caffe_root = './'
os.chdir(caffe_root)
sys.path.insert(0, os.path.join(caffe_root, 'python'))
import caffe

from google.protobuf import text_format
from caffe.proto import caffe_pb2
from caffe.model_libs import *

####### you are supposed to run this script at the CAFFE ROOT ########################

network_name = "ssd"  #your neural net name, need to config
dataset_name = "VOC0712"#your dataset name, need to config
model_name = "{}_{}".format(network_name,dataset_name)
job_dir = "examples/{}/{}".format(network_name, model_name)
prototxt_dir = "{}/prototxt".format(job_dir)
trainLog_dir = "{}/log".format(job_dir)
trainData_dir = "{}/data".format(job_dir)
trainModel_dir = "{}/model".format(job_dir)
img_save_dir = "{}/result/detect".format(job_dir)

# the caffemodel you want to use
model_weights = "{}/ssd_VOC0712_iter_120000.caffemodel".format(trainModel_dir)#need to config

deploy_net_file = "{}/deploy.prototxt".format(prototxt_dir)

# used to show label name
labelmap_file = "{}/labelmap_voc.prototxt".format(trainData_dir)
# image_resize has to be matched to the input size of your network
image_resize = 300 #need to config

# source_file can be an image file, a directory, a video file or the camera id
#sour
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值