一 安装与下载
- 下载与安装anaconda2
去官网下载Anaconda2-5.3.1-Windows-x86_64.exe版本并安装。 - 下载与安装cuda,cudnn
去官网下载cuda9.2和对应的cudnn,安装cuda_9.2.148_win10.exe和对应的cudnn-9.2-windows10-x64-v7.6.5.32 - 下载visual studio2013
- 下载Caffe-SSD的microsoft版本:https://github.com/conner99/caffe
- VOC2007 and VOC2012 dataset可以在下方链接下载
http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
- 下载OpenCV3.0
在OpenCV官网下载3.0版本源代码,解压后放到\NugetPackages目录下,不要使用nuget下载的OpenCV版本,不要使用nuget下载的OpenCV版本,不要使用nuget下载的OpenCV版本。

训练数据准备
- 执行data/VOC0712中的create_list.sh生成test.txt,test_name_size.txt,trainval.txt
create_list.sh文件修改如下:
1,root_dir修改成标注文件的绝对路径
2,sub_dir修改成imageSets/Main/
3,“# Generate image name and size infomation.”这行下方的条件语句修改为“$bash_dir/…/get_image_size $root_dir $dst_file bashdir/bash_dir/bashdir/dataset"_name_size.txt"”
4,最后一行增加“read -p “Press any key to continue.” var”
所有内容如下:
#!/bin/bash
root_dir=E:/workspace/Python/caffe-ssd-microsoft/data/VOCdevkit/
sub_dir=ImageSets/Main/
bash_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
for dataset in trainval test
do
dst_file=$bash_dir/$dataset.txt
if [ -f $dst_file ]
then
rm -f $dst_file
fi
for name in VOC2007
do
if [[ $dataset == "test" && $name == "VOC2012" ]]
then
continue
fi
echo "Create list for $name $dataset..."
dataset_file=$root_dir/$name/$sub_dir/$dataset.txt
img_file=$bash_dir/$dataset"_img.txt"
cp $dataset_file $img_file
sed -i "s/^/$name\/JPEGImages\//g" $img_file
sed -i "s/$/.jpg/g" $img_file
label_file=$bash_dir/$dataset"_label.txt"
cp $dataset_file $label_file
sed -i "s/^/$name\/Annotations\//g" $label_file
sed -i "s/$/.xml/g" $label_file
paste -d' ' $img_file $label_file >> $dst_file
rm -f $label_file
rm -f $img_file
done
# Generate image name and size infomation.
if [ $dataset == "test" ]
then
$bash_dir/../get_image_size $root_dir $dst_file $bash_dir/$dataset"_name_size.txt"
fi
# Shuffle trainval file.
if [ $dataset == "trainval" ]
then
rand_file=$dst_file.random
cat $dst_file | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' > $rand_file
mv $rand_file $dst_file
fi
done
read -p "Press any key to continue." var
使用git Bash工具运行create_list.sh文件命令为sh create_list.sh,运行后确认生成的test.txt、test_name_size.txt、trainval.txt三个文件存在内容。类似如下:

- 修改labelmap_voc.prototxt保留0号背景标签,其余的按照其格式根据样本分类数目或修改或添加删除增加自己的item类型。
- 运行create_data.sh文件生成对应的test_lmdb和trainval_lmdb
1,右键编辑create_data.sh文件,去掉examples/$dataset_name,并添加最后一行read -p “Press any key to continue.” Var
2,修改data_root_dir为工程路径
cur_dir=$(cd $( dirname ${BASH_SOURCE[0]} ) && pwd )
root_dir=$cur_dir/../..
cd $root_dir
redo=1
data_root_dir="E:/workspace/Python/caffe-ssd-microsoft/"
dataset_name="VOC0712"
mapfile=$root_dir/data/$dataset_name/"labelmap_voc.prototxt"
anno_type="detection"
db="lmdb"
min_dim=0
max_dim=0
width=0
height=0
extra_cmd="--encode-type=jpg --encoded"
if [ $redo ]
then
extra_cmd="$extra_cmd --redo"
fi
for subset in test trainval
do
python $root_dir/scripts/create_annoset.py --anno-type=$anno_type --label-map-file=$mapfile --min-dim=$min_dim --max-dim=$max_dim --resize-width=$width --resize-height=$height --check-label $extra_cmd $data_root_dir $root_dir/data/$dataset_name/$subset.txt $data_root_dir/$dataset_name/$db/$dataset_name"_"$subset"_"$db
done
read -p "Press any key to continue." var
- 运行ssd_pascal.py(修改num_class,num_gpus=len(gpulist))生成jobs,models文件夹
1,从编译源代码路径examples\ssd下(并非生成代码路径)将.py脚本拷贝至生成代码路径Build、x64\下,将ssd_pascal.py再拷贝至生成的caffe根目录下(E:\workspace\Python\caffe-ssd-microsoft\windows)
将run_soon = True修改为run_soon = False,use_cpu = False
2, 修改train_data为 “…/data/VOC0712/lmdb/trainval_lmdb”
3,修改test_data为"…/data/VOC0712/lmdb/test_lmdb"
4,修改name_size_file = “…/data/VOC0712/test_name_size.txt”
5,修改pretrain_model = “…/data/VOC0712/VGG_ILSVRC_16_layers_fc_reduced.caffemodel”
6,修改label_map_file = “…/data/VOC0712/labelmap_voc.prototxt”
7,修改num_classes为实际类型数
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):
use_relu = True
# Add additional convolutional layers.
from_layer = net.keys()[-1]
# TODO(weiliu89): Construct the name using the last layer to avoid duplication.
out_layer = "conv6_1"
ConvBNLayer(net, from_layer, out_layer, use_batchnorm, use_relu, 256, 1, 0, 1)
from_layer = out_layer
out_layer = "conv6_2"
ConvBNLayer(net, from_layer, out_layer, use_batchnorm, use_relu, 512, 3, 1, 2)
for i in xrange(7, 9):
from_layer = out_layer
out_layer = "conv{}_1".format(i)
ConvBNLayer(net, from_layer, out_layer, use_batchnorm, use_relu, 128, 1, 0, 1)
from_layer = out_layer
out_layer = "conv{}_2".format(i)
ConvBNLayer(net, from_layer, out_layer, use_batchnorm, use_relu, 256, 3, 1, 2)
# Add global pooling layer.
name = net.keys()[-1]
net.pool6 = L.Pooling(net[name], pool=P.Pooling.AVE, global_pooling=True)
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 = False
# 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
# Set true if you want to train with CPU
use_cpu = False
# The database file for training data. Created by data/VOC0712/create_data.bat
train_data = "../data/VOC0712/lmdb/trainval_lmdb"
# The database file for testing data. Created by data/VOC0712/create_data.bat
test_data = "../data/VOC0712/lmdb/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,
'max_scale': 1.0,
'min_aspect_ratio': 0.5,
'max_aspect_ratio': 2.0,
},
'sample_constraint': {
'min_jaccard_overlap': 0.1,
},
'max_trials': 50,
'max_sample': 1,
},
{
'sampler': {
'min_scale': 0.3,
'max_scale': 1.0,
'min_aspect_ratio': 0.5,
'max_aspect_ratio': 2.0,
},
'sample_constraint': {
'min_jaccard_overlap': 0.3,
},
'max_trials': 50,
'max_sample': 1,
},
{
'sampler': {
'min_scale': 0.3,
'max_scale': 1.0,
'min_aspect_ratio': 0.5,
'max_aspect_ratio': 2.0,
},
'sample_constraint': {
'min_jaccard_overlap': 0.5,
},
'max_trials': 50,
'max_sample': 1,
},
{
'sampler': {
'min_scale': 0.3,
'max_scale': 1.0,
'min_aspect_ratio': 0.5,
'max_aspect_ratio': 2.0,
},
'sample_constraint': {
'min_jaccard_overlap': 0.7,
},
'max_trials': 50,
'max_sample': 1,
},
{
'sampler': {
'min_scale': 0.3,
'max_scale': 1.0,
'min_aspect_ratio': 0.5,
'max_aspect_ratio': 2.0,
},
'sample_constraint': {
'min_jaccard_overlap': 0.9,
},
'max_trials': 50,
'max_sample': 1,
},
{
'sampler': {
'min_scale': 0.3,
'max_scale': 1.0,
'min_aspect_ratio': 0.5,
'max_aspect_ratio': 2.0,
},
'sample_constraint': {
'max_jaccard_overlap': 1.0,
},
'max_trials': 50,
'max_sample': 1,
},
]
train_transform_param = {
'mirror': True,
'mean_value': [104, 117, 123],
'resize_param': {
'prob': 1,
'resize_mode': P.Resize.WARP,
'height': resize_height,
'width': resize_width,
'interp_mode': [
P.Resize.LINEAR,
P.Resize.AREA,
P.Resize.NEAREST,
P.Resize.CUBIC,
P.Resize.LANCZOS4,
],
},
'emit_constraint': {
'emit_type': caffe_pb2.EmitConstraint.CENTER,
}
}
test_transform_param = {
'mean_value': [104, 117, 123],
'resize_param': {
'prob': 1,
'resize_mode': P.Resize.WARP,
'height': resize_height,
'width': resize_width,
'interp_mode': [P.Resize.LINEAR],
},
}
# If true, use batch norm for all newly added layers.
# Currently only the non batch norm version has been tested.
use_batchnorm = False
# Use different initial learning rate.
if use_batchnorm:
base_lr = 0.0004
else:
# A learning rate for batch_size = 1, num_gpus = 1.
base_lr = 0.00004
# Modify the job name if you want.
job_name = "SSD_{}".format(resize)
# The name of the model. Modify it if you want.
model_name = "VGG_VOC0712_{}".format(job_name)
# Directory which stores the model .prototxt file.
save_dir = "models/VGGNet/VOC0712/{}".format(job_name)
# Directory which stores the snapshot of models.
snapshot_dir = "models/VGGNet/VOC0712/{}".format(job_name)
# Directory which stores the job script and log file.
job_dir = "jobs/VGGNet/VOC0712/{}".format(job_name)
# Directory which stores the detection results.
output_result_dir = "data/VOC0712/results/{}/Main".format(job_name)
# model definition files.
train_net_file = "{}/train.prototxt".format(save_dir)
test_net_file = "{}/test.prototxt".format(save_dir)
deploy_net_file = "{}/deploy.prototxt".format(save_dir)
solver_file = "{}/solver.prototxt".format(save_dir)
# snapshot prefix.
snapshot_prefix = "{}/{}".format(snapshot_dir, model_name)
# job script path.
job_file = "{}/{}_train.bat".format(job_dir, model_name)
# Stores the test image names and sizes. Created by data/VOC0712/create_list.sh
name_size_file = "../data/VOC0712/test_name_size.txt"
# The pretrained model. We use the Fully convolutional reduced (atrous) VGGNet.
pretrain_model = "../data/VOC0712/VGG_ILSVRC_16_layers_fc_reduced.caffemodel"
# Stores LabelMapItem.
label_map_file = "../data/VOC0712/labelmap_voc.prototxt"
# MultiBoxLoss parameters.
num_classes = 21
share_location = True
background_label_id=0
train_on_diff_gt = True
normalization_mode = P.Loss.VALID
code_type = P.PriorBox.CENTER_SIZE
neg_pos_ratio = 3.
loc_weight = (neg_pos_ratio + 1.) / 4.
multibox_loss_param = {
'loc_loss_type': P.MultiBoxLoss.SMOOTH_L1,
'conf_loss_type': P.MultiBoxLoss.SOFTMAX,
'loc_weight': loc_weight,
'num_classes': num_classes,
'share_location': share_location,
'match_type': P.MultiBoxLoss.PER_PREDICTION,
'overlap_threshold': 0.5,
'use_prior_for_matching': True,
'background_label_id': background_label_id,
'use_difficult_gt': train_on_diff_gt,
'do_neg_mining': True,
'neg_pos_ratio': neg_pos_ratio,
'neg_overlap': 0.5,
'code_type': code_type,
}
loss_param = {
'normalization': normalization_mode,
}
# parameters for generating priors.
# minimum dimension of input image
min_dim = 300
# conv4_3 ==> 38 x 38
# fc7 ==> 19 x 19
# conv6_2 ==> 10 x 10
# conv7_2 ==> 5 x 5
# conv8_2 ==> 3 x 3
# pool6 ==> 1 x 1
mbox_source_layers = ['conv4_3', 'fc7', 'conv6_2', 'conv7_2', 'conv8_2', 'pool6']
# in percent %
min_ratio = 20
max_ratio = 95
step = int(math.floor((max_ratio - min_ratio) / (len(mbox_source_layers) - 2)))
min_sizes = []
max_sizes = []
for ratio in xrange(min_ratio, max_ratio + 1, step):
min_sizes.append(min_dim * ratio / 100.)
max_sizes.append(min_dim * (ratio + step) / 100.)
min_sizes = [min_dim * 10 / 100.] + min_sizes
max_sizes = [[]] + max_sizes
aspect_ratios = [[2], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]]
# L2 normalize conv4_3.
normalizations = [20, -1, -1, -1, -1, -1]
# variance used to encode/decode prior bboxes.
if code_type == P.PriorBox.CENTER_SIZE:
prior_variance = [0.1, 0.1, 0.2, 0.2]
else:
prior_variance = [0.1]
flip = True
clip = True
# Solver parameters.
# Defining which GPUs to use.
gpus = "0" #"0,1,2,3"
gpulist = gpus.split(",")
num_gpus = len(gpulist)
# Set true if you want to train with CPU
use_cpu = False
# Divide the mini-batch to different GPUs.
if use_cpu:
num_gpus = 0
batch_size = 2 # 32
accum_batch_size = 32
iter_size = accum_batch_size / batch_size
solver_mode = P.Solver.CPU
device_id = 0
batch_size_per_device = batch_size
if num_gpus > 0:
batch_size_per_device = int(math.ceil(float(batch_size) / num_gpus))
iter_size = int(math.ceil(float(accum_batch_size) / (batch_size_per_device * num_gpus)))
solver_mode = P.Solver.GPU
device_id = int(gpulist[0])
if normalization_mode == P.Loss.NONE:
base_lr /= batch_size_per_device
elif normalization_mode == P.Loss.VALID:
base_lr *= 25. / loc_weight
elif normalization_mode == P.Loss.FULL:
# Roughly there are 2000 prior bboxes per image.
# TODO(weiliu89): Estimate the exact # of priors.
base_lr *= 2000.
# Which layers to freeze (no backward) during training.
freeze_layers = ['conv1_1', 'conv1_2', 'conv2_1', 'conv2_2']
# Evaluate on whole test set.
num_test_image = 4952
test_batch_size = 1
test_iter = num_test_image / test_batch_size
solver_param = {
# Train parameters
'base_lr': base_lr,
'weight_decay': 0.0005,
'lr_policy': "step",
'stepsize': 40000,
'gamma': 0.1,
'momentum': 0.9,
'iter_size': iter_size,
'max_iter': 60000,
'snapshot': 40000,
'display': 10,
'average_loss': 10,
'type': "SGD",
'solver_mode': solver_mode,
'device_id': device_id,
'debug_info': False,
'snapshot_after_train': True,
# Test parameters
'test_iter': [test_iter],
'test_interval': 10000,
'eval_type': "detection",
'ap_version': "11point",
'test_initialization': False,
}
# parameters for generating detection output.
det_out_param = {
'num_classes': num_classes,
'share_location': share_location,
'background_label_id': background_label_id,
'nms_param': {'nms_threshold': 0.45, 'top_k': 400},
'save_output_param': {
'output_directory': output_result_dir,
'output_name_prefix': "comp4_det_test_",
'output_format': "VOC",
'label_map_file': label_map_file,
'name_size_file': name_size_file,
'num_test_image': num_test_image,
},
'keep_top_k': 200,
'confidence_threshold': 0.01,
'code_type': code_type,
}
# parameters for evaluating detection results.
det_eval_param = {
'num_classes': num_classes,
'background_label_id': background_label_id,
'overlap_threshold': 0.5,
'evaluate_difficult_gt': False,
'name_size_file': name_size_file,
}
### Hopefully you don't need to change the following ###
# Check file.
check_if_exist(train_data)
check_if_exist(test_data)
check_if_exist(label_map_file)
check_if_exist(pretrain_model)
make_if_not_exist(save_dir)
make_if_not_exist(job_dir)
make_if_not_exist(snapshot_dir)
# Create train net.
net = caffe.NetSpec()
net.data, net.label = CreateAnnotatedDataLayer(train_data, batch_size=batch_size_per_device,
train=True, output_label=True, label_map_file=label_map_file,
transform_param=train_transform_param, batch_sampler=batch_sampler)
VGGNetBody(net, from_layer='data', fully_conv=True, reduced=True, dilated=True,
dropout=False, freeze_layers=freeze_layers)
AddExtraLayers(net, use_batchnorm)
mbox_layers = CreateMultiBoxHead(net, data_layer='data', from_layers=mbox_source_layers,
use_batchnorm=use_batchnorm, min_sizes=min_sizes, max_sizes=max_sizes,
aspect_ratios=aspect_ratios, normalizations=normalizations,
num_classes=num_classes, share_location=share_location, flip=flip, clip=clip,
prior_variance=prior_variance, kernel_size=3, pad=1)
# Create the MultiBoxLossLayer.
name = "mbox_loss"
mbox_layers.append(net.label)
net[name] = L.MultiBoxLoss(*mbox_layers, multibox_loss_param=multibox_loss_param,
loss_param=loss_param, include=dict(phase=caffe_pb2.Phase.Value('TRAIN')),
propagate_down=[True, True, False, False])
with open(train_net_file, 'w') as f:
print('name: "{}_train"'.format(model_name), file=f)
print(net.to_proto(), file=f)
shutil.copy(train_net_file, job_dir)
# Create test net.
net = caffe.NetSpec()
net.data, net.label = CreateAnnotatedDataLayer(test_data, batch_size=test_batch_size,
train=False, output_label=True, label_map_file=label_map_file,
transform_param=test_transform_param)
VGGNetBody(net, from_layer='data', fully_conv=True, reduced=True, dilated=True,
dropout=False, freeze_layers=freeze_layers)
AddExtraLayers(net, use_batchnorm)
mbox_layers = CreateMultiBoxHead(net, data_layer='data', from_layers=mbox_source_layers,
use_batchnorm=use_batchnorm, min_sizes=min_sizes, max_sizes=max_sizes,
aspect_ratios=aspect_ratios, normalizations=normalizations,
num_classes=num_classes, share_location=share_location, flip=flip, clip=clip,
prior_variance=prior_variance, kernel_size=3, pad=1)
conf_name = "mbox_conf"
if multibox_loss_param["conf_loss_type"] == P.MultiBoxLoss.SOFTMAX:
reshape_name = "{}_reshape".format(conf_name)
net[reshape_name] = L.Reshape(net[conf_name], shape=dict(dim=[0, -1, num_classes]))
softmax_name = "{}_softmax".format(conf_name)
net[softmax_name] = L.Softmax(net[reshape_name], axis=2)
flatten_name = "{}_flatten".format(conf_name)
net[flatten_name] = L.Flatten(net[softmax_name], axis=1)
mbox_layers[1] = net[flatten_name]
elif multibox_loss_param["conf_loss_type"] == P.MultiBoxLoss.LOGISTIC:
sigmoid_name = "{}_sigmoid".format(conf_name)
net[sigmoid_name] = L.Sigmoid(net[conf_name])
mbox_layers[1] = net[sigmoid_name]
net.detection_out = L.DetectionOutput(*mbox_layers,
detection_output_param=det_out_param,
include=dict(phase=caffe_pb2.Phase.Value('TEST')))
net.detection_eval = L.DetectionEvaluate(net.detection_out, net.label,
detection_evaluate_param=det_eval_param,
include=dict(phase=caffe_pb2.Phase.Value('TEST')))
with open(test_net_file, 'w') as f:
print('name: "{}_test"'.format(model_name), file=f)
print(net.to_proto(), file=f)
shutil.copy(test_net_file, job_dir)
# Create deploy net.
# Remove the first and last layer from test net.
deploy_net = net
with open(deploy_net_file, 'w') as f:
net_param = deploy_net.to_proto()
# Remove the first (AnnotatedData) and last (DetectionEvaluate) layer from test net.
del net_param.layer[0]
del net_param.layer[-1]
net_param.name = '{}_deploy'.format(model_name)
net_param.input.extend(['data'])
net_param.input_shape.extend([
caffe_pb2.BlobShape(dim=[1, 3, resize_height, resize_width])])
print(net_param, file=f)
shutil.copy(deploy_net_file, job_dir)
# Create solver.
solver = caffe_pb2.SolverParameter(
train_net=train_net_file,
test_net=[test_net_file],
snapshot_prefix=snapshot_prefix,
**solver_param)
with open(solver_file, 'w') as f:
print(solver, file=f)
shutil.copy(solver_file, job_dir)
max_iter = 0
# Find most recent snapshot.
for file in os.listdir(snapshot_dir):
if file.endswith(".solverstate"):
basename = os.path.splitext(file)[0]
iter = int(basename.split("{}_iter_".format(model_name))[1])
if iter > max_iter:
max_iter = iter
train_src_param = ''
if os.path.isfile(pretrain_model):
train_src_param = '\t--weights={} ^\n'.format(os.path.normpath(pretrain_model))
if resume_training:
if max_iter > 0:
train_src_param = '\t--snapshot={}_iter_{}.solverstate ^\n'.format(os.path.normpath(snapshot_prefix), max_iter)
if remove_old_models:
# Remove any snapshots smaller than max_iter.
for file in os.listdir(snapshot_dir):
if file.endswith(".solverstate"):
basename = os.path.splitext(file)[0]
iter = int(basename.split("{}_iter_".format(model_name))[1])
if max_iter > iter:
os.remove("{}/{}".format(snapshot_dir, file))
if file.endswith(".caffemodel"):
basename = os.path.splitext(file)[0]
iter = int(basename.split("{}_iter_".format(model_name))[1])
if max_iter > iter:
os.remove("{}/{}".format(snapshot_dir, file))
# Create job file.
with open(job_file, 'w') as f:
f.write('SET GLOG_logtostderr=1\n')
f.write('set Datum=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%\n')
f.write('set Uhrzeit=%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2%\n')
f.write('set TIMESTAMP=%Datum%_%Uhrzeit%\n')
f.write('\n'.format(caffe_root))
f.write('cd {}\n'.format(caffe_root))
f.write('"Build\{}\Release\caffe" train ^\n'.format('x64'))
f.write('\t--solver={} ^\n'.format(os.path.normpath(solver_file)))
f.write(train_src_param)
if solver_param['solver_mode'] == P.Solver.GPU:
f.write('\t--gpu {} 2>&1 | "tools\mtee" "{}\{}-train-%TIMESTAMP%.log"\n'.format(gpus, os.path.normpath(job_dir), model_name))
else:
f.write('\t2>&1 | "tools\mtee" "{}\{}-train-%TIMESTAMP%.log"\n'.format(os.path.normpath(job_dir), model_name))
f.write('read -p "Press any key to continue." var')
# Copy the python script to job_dir.
py_file = os.path.abspath(__file__)
shutil.copy(py_file, job_dir)
# Run the job.
os.chmod(job_file, stat.S_IRWXU)
if run_soon:
subprocess.call(os.path.normpath(job_file), shell=True)
- 进入job把caffe train的命拷贝出来在cmd中运行。
caffe.exe train --solver=./models/VGGNet/VOC0712/SSD_300x300/solver.prototxt --weights=./VOC0712/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
修改models里的test.prototxt的force_color:true,batch_size以及相关路径
1,data_param里的source:“E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/lmdb/VOC0712_test_lmdb”
2,annotated_data_param 里的 label_map_file: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/labelmap_voc.prototxt”
3,save_output_param 里的output_directory: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/results/SSD_300x300/Main”
4,label_map_file: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/labelmap_voc.prototxt”
5,name_size_file: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/test_name_size.txt”
6,num_test_image修改为实际test的图片数量
7,detection_evaluate_param 里的name_size_file: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/test_name_size.txt”
train.prototxt文件里的
1,data_param 的source: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/lmdb/VOC0712_trainval_lmdb”
2,batch_sampler 的 label_map_file: “E:/workspace/Python/caffe-ssd-microsoft/data/VOC0712/labelmap_voc.prototxt”
- 修改solver.prototxt中的参数,具体参考网上solver各参数的含义,主要是迭代次数。
- 在cmd中运行上面复制出来的指令
caffe.exe train --solver=./models/VGGNet/VOC0712/SSD_300x300/solver.prototxt --weights=./VOC0712/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
工程编译
-
打开caffe-master文件夹,然后看到一个windows文件夹,然后继续打开windows文件夹,看到里面一个CommonSettings.props.example文件,复制出来一份,并改名字为CommonSettings.props。
使用vs2013打开windows下的caffe.sln工程进行属性设置和参数修改。
如果libcaffe和test_all显示加载失败,关闭VS,打开 CUDA 安装路径中的 MSbuildExtensions 文件夹,如果你在之前安装时选的是默认路径,那么它应当在 c 盘 / Program File/NVIDIA GPU Cpmputing Toolkit/CUDA/9.2/extras/visual_studio_integration 里的所有文件复制到 C 盘 / Program File(x86)/MSBuild/Microsoft.Cpp/v4.0(这里取决于你安装的版本)/V120/BuildCustomizations 文件夹下,替换目标中的文件。这时打开VS,发现他俩不再显示加载失败了。


-
修改CommonSettings.props 文件的内容

-
2,编译顺序:libcafffe->caffe->pycaffe->get_image_size->conver_annoset->conver_imageset
编译libcaffe:右击右侧libcaffe,选择属性,打开如下libcaffe属性页:按照如下修改



可能遇到的问题
1,error MSB3721: 命令“……”已退出,返回代码为2
解决:有多种情况会提示这个错误。
注释掉 detection_output_layer.hpp和detection_output_layer.cu和detection_output_layer.cpp有关regex 和rv的引用和语句 。以及CommonSettings.props里的cudnn目录不要有(如果已经把cudnn的文件复制到了cuda目录里)
2,编译项目,报错“未能生成object文件(视警告为错误)”,解决方法:右击选择属性->配置属性->c/c+±>常规,将“警告视为错误”的选项改“否”
3,GLOG_NO_ABBREVIATED_SEVERITIES
解决:在工程加上预编译宏GLOG_NO_ABBREVIATED_SEVERITIES
C/C++ --> 预处理器 --> 预处理器定义 --> 加上GLOG_NO_ABBREVIATED_SEVERITIES
4,找不到".\caffe\3rdparty\hungarian.h"文件
解决:在路径.\caffe-master\include\caffe\3rdparty\下添加hungarian.h文件。编译项目,报错:找不到".\src\caffe\3rdparty\hungarian.cpp"文件,在路径.\caffe-master\src\caffe\3rdparty\下添加hungarian.cpp文件
这两个文件可以在github上搜索得到。

5,expected an identifier in caffe.pb.h
解决:修改bbox_util.cu,注释掉所有带thrust的语句,修改detection_output_layer.cu和detection_output_layer.cpp文件,注释掉所有regex和rv的语句,修改detection_output_layer.hpp,注释#include“boost/regex.hpp”
6,Too few arguments…的错误
全局搜索找到cudnnSetConvolution2dDescriptor函数,为该函数最后增加一个参数为:dataType::type。
7,gflags,glog等的错误就是直接重新下载对应的库。
1410

被折叠的 条评论
为什么被折叠?



