資源簡介
基于caffe訓練的SSD300x300物體檢測模型,結合opencv一起使用。
代碼片段和文件信息
from?__future__?import?print_function
import?caffe
from?caffe.model_libs?import?*
from?google.protobuf?import?text_format
import?math
import?os
import?shutil
import?stat
import?subprocess
import?sys
#?Add?extra?layers?on?top?of?a?“base“?network?(e.g.?VGGNet?or?Inception).
def?AddExtralayers(net?use_batchnorm=True?lr_mult=1):
????use_relu?=?True
????#?Add?additional?convolutional?layers.
????#?19?x?19
????from_layer?=?net.keys()[-1]
????#?TODO(weiliu89):?Construct?the?name?using?the?last?layer?to?avoid?duplication.
????#?10?x?10
????out_layer?=?“conv6_1“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?256?1?0?1
????????lr_mult=lr_mult)
????from_layer?=?out_layer
????out_layer?=?“conv6_2“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?512?3?1?2
????????lr_mult=lr_mult)
????#?5?x?5
????from_layer?=?out_layer
????out_layer?=?“conv7_1“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?128?1?0?1
??????lr_mult=lr_mult)
????from_layer?=?out_layer
????out_layer?=?“conv7_2“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?256?3?1?2
??????lr_mult=lr_mult)
????#?3?x?3
????from_layer?=?out_layer
????out_layer?=?“conv8_1“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?128?1?0?1
??????lr_mult=lr_mult)
????from_layer?=?out_layer
????out_layer?=?“conv8_2“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?256?3?0?1
??????lr_mult=lr_mult)
????#?1?x?1
????from_layer?=?out_layer
????out_layer?=?“conv9_1“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?128?1?0?1
??????lr_mult=lr_mult)
????from_layer?=?out_layer
????out_layer?=?“conv9_2“
????ConvBNlayer(net?from_layer?out_layer?use_batchnorm?use_relu?256?3?0?1
??????lr_mult=lr_mult)
????return?net
###?Modify?the?following?parameters?accordingly?###
#?The?directory?which?contains?the?caffe?code.
#?We?assume?you?are?running?the?script?at?the?CAFFE_ROOT.
caffe_root?=?os.getcwd()
#?Set?true?if?you?want?to?start?training?right?after?generating?all?files.
run_soon?=?True
#?Set?true?if?you?want?to?load?from?most?recently?saved?snapshot.
#?Otherwise?we?will?load?from?the?pretrain_model?defined?below.
resume_training?=?True
#?If?true?Remove?old?model?files.
remove_old_models?=?False
#?The?database?file?for?training?data.?Created?by?data/VOC0712Plus/create_data.sh
train_data?=?“examples/VOC0712Plus/VOC0712Plus_trainval_lmdb“
#?The?database?file?for?testing?data.?Created?by?data/VOC0712Plus/create_data.sh
test_data?=?“examples/VOC0712Plus/VOC0712Plus_test_lmdb“
#?Specify?the?batch?sampler.
resize_width?=?300
resize_height?=?300
resize?=?“{}x{}“.format(resize_width?resize_height)
batch_sampler?=?[
????????{
????????????????‘sampler‘:?{
????????????????????????}
????????????????‘max_trials‘:?1
????????????????‘max_sample‘:?1
????????}
????????{
????????????????‘sampler‘:?{
????????????????????????‘min_scale‘:?0.3
???????????????
評論
共有 條評論