sunnyl95 / r-fcn Goto Github PK
View Code? Open in Web Editor NEW制作VOC2007数据集用于R-FCN训练
制作VOC2007数据集用于R-FCN训练
在传统的FCN中,每个图像只生成一个score map, 表示每个像素的值表示该像素是否属于
目标的概率。
在 InstanceFCN中,作者会生成kk个score maps, 每个像素的值表示该像素是否属于某一
类的某个位置的概率。
R-FCN 提出了 position-sensitive score map "位置敏感得分地图",借鉴InstanceFCN的思
想,为(C+1)个类别生成kk*(C+1)个得分地图
当 k = 3时,
左上,中上,右上
左中,中中,右中
左下,中下,右下
On the top branch,会生成k2 个Instance score map,也就是每个像素都会有k2个不同的
值,即解决了相同像素在不同Instance中有不同的响应。然后经过assembling module就
可以生成all Instance map。但是并不是所有的响应都有Instance出现。所以作者在bottom
branch,计算了objectness score map。将两者融合就能获得最终的Instance
Segmentation
1.安装编译完caffe后,其主目录下有:
2.训练模型之前需要先准备好训练数据MNIST,执行以下命令可以下载MNIST数据库:
3.由于caffe支持的数据类型不包括图像类型,所以常规做法需要将图像类型转为lmdb类型。
4.准备好数据之后,我们需要定义我们的网络模型,在caffe中是通过.prototxt配置文件来定义的,执行以下命令:
#caffe是如何定义网络的?
#输入层(数据层)
layer{
name:"mnist" //表示层名
type:"Date" //表示层的类型
top:"data"
top:"lable"
include{
phase:TRAIN //表示仅在训练阶段起作用
}
transform_param{
scale: 0.00390625 //将图像像素归一化
}
data_param{
source:"example/mnist/mnist_train_imdb" //数据来源
batch_size: 64 //训练师每个迭代的输入样本数量
backend: LMDB //数据类型
}
}
#卷积层
layer{
name: "conv1"
type: "Convolution"
bottom: "data" //输入是data
top:"conv1" //输出是卷积特征
param{
lr_mult: 1 //权重参数w的学习率倍数
}
param{
lr_mult: 2 //偏执参数b的学习率倍数
}
convolution_param{
num_output: 20
kernel_size :5
stride: 1
weight_filer{ //权重参数w的初始化方案,使用xavier算法
type: "xavier"
}
bias_filler{
type: "constant" //偏执参数b初始化为常数,一般为0
}
}
}
#下采样层(pool)
layer{
name: "pool1"
type: "Pooling"
bottom: "conv1"
top:"pool1"
pooling_param{
pool: MAX
kernel_size: 2
stride: 2
}
}
#全连接层
layer{
name: "ip1"
type: "InnerProduct"
bottom: "pool2"
top:"ip1"
param{
lr_mult: 1
}
param{
lr_mult: 2
}
inner_product_param{
num_output: 500
weight_filer{
type: "xavier"
}
bias_filler{
type: "constant"
}
}
}
#非线性层
layer{
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
#准确率层(计算准确率)
layer{
name: "accuracy"
type: "Accuracy"
bottom: "ip2"
bottom: "lable"
top: "accuracy"
include{
phase: TEST
}
}
#损失估计层
layer{
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip2"
bottom: "lable"
top:"loss"
}
#定义完网络模型,还需要配置关于模型优化的文件:
制作VOC2007数据集用于Faster-RCNN训练:VOC2007格式是faster-RCNN中官方给出的用于训练的数据集,把它下载下来用frcnn/tool里的训练程序跑一跑就可以得到自己的训练网络了,首先说明一下我们需要准备的文件:
VOC2007格式必须为JPG格式,并且图片是统一的六位数字,从000001开始。那我们也需要将所有训练图片重命名为此。Python代码如下:
`import os
import numpy as np
import re
import pandas as pd
dire = r'F:\dataset\UAV'
a = os.listdir(dire)
mode = re.compile(r'\d+')
for i in range(n):
ids[i] = mode.findall(a[i])[0]
a[i] = dire + '\' + a[i]
b = np.zeros(n).astype(np.str)
pos = 6
for i in range(n):
c = str(i)
ze = pos-len(c)
b[i] = '0'*ze+str(i)
b[i] = dire +'\'+b[i]+'.jpg'
for i in range(n):
os.rename(a[i],b[i])`
利用图片标注工具lableImg进行标注,具体参照
[https://blog.csdn.net/jesse_mx/article/details/53606897]
新建一个文件夹,名字为Annotations,将xml文件全部放到该文件夹里。
新建一个文件夹,名字为JPEGImages,将所有的训练图片放到该文件夹里。
新建文件夹,命名为ImageSets,在ImageSets里再新建文件夹,命名为Main
我们可以通过xml名字(或图片名),生成四个txt文件,即:
train.txt test.txt trainval.txt val.txt
内容:
000001
000002
........
即图片名字(无后缀),test.txt是测试集,train.txt是训练集,val.txt是验证集,
trainval.txt是训练和验证集.VOC2007中,trainval大概是整个数据集的50%,test也大概
是整个数据集的50%;train大概是trainval的50%,val大概是trainval的50%。
%%
%该代码根据已生成的xml,制作VOC2007数据集中的trainval.txt;train.txt;test.txt和val.txt
%trainval占总数据集的50%,test占总数据集的50%;train占trainval的50%,val占trainval的50%;
%上面所占百分比可根据自己的数据集修改,如果数据集比较少,test和val可少一些
%%
%注意修改下面四个值
xmlfilepath='E:\Annotations';
txtsavepath='E:\ImageSets\Main';
trainval_percent=0.5;%trainval占整个数据集的百分比,剩下部分就是test所占百分比
train_percent=0.5;%train占trainval的百分比,剩下部分就是val所占百分比
%%
xmlfile=dir(xmlfilepath);
numOfxml=length(xmlfile)-2;%减去.和.. 总的数据集大小
trainval=sort(randperm(numOfxml,floor(numOfxml*trainval_percent)));
test=sort(setdiff(1:numOfxml,trainval));
trainvalsize=length(trainval);%trainval的大小
train=sort(trainval(randperm(trainvalsize,floor(trainvalsize*train_percent))));
val=sort(setdiff(trainval,train));
ftrainval=fopen([txtsavepath 'trainval.txt'],'w');
ftest=fopen([txtsavepath 'test.txt'],'w');
ftrain=fopen([txtsavepath 'train.txt'],'w');
fval=fopen([txtsavepath 'val.txt'],'w');
for i=1:numOfxml
if ismember(i,trainval)
fprintf(ftrainval,'%s\n',xmlfile(i+2).name(1:end-4));
if ismember(i,train)
fprintf(ftrain,'%s\n',xmlfile(i+2).name(1:end-4));
else
fprintf(fval,'%s\n',xmlfile(i+2).name(1:end-4));
end
else
fprintf(ftest,'%s\n',xmlfile(i+2).name(1:end-4));
end
end
fclose(ftrainval);
fclose(ftrain);
fclose(fval);
fclose(ftest);
这四个txt放在ImageSets\Main中。
这样,数据集就基本做好了。然后新建文件夹,名字为logos(第0步确定的名字),将上面三个文件夹放到这里,即logos文件夹里有三个文件夹:
将logos文件夹拷贝到datasets\VOCdevkit2007里就可以了。
(或者替换voc2007数据集中的Annotations、ImageSets和JPEGImages,免去一些训练的修改)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.