所以首先理解AnnotatedDutam結構。
知乎上:https://zhuanlan.zhihu.com/p/76318150 講述比較容易理解,可參考。
下面這幅圖也比較直觀:
AnnotatedDatum就是caffe用来保存数据对象的一种数据结构了,AnnotatedDatum中又包含一个Datum类型数据(用于保存图像内容)和一个基于google的ProtoBuf(一种接口描述语言)的自定义类型数据annotation_group(用于保存检测框),此外AnnotatedDatum自身也是Datum类型数据,Datum类似于Dict,是lmdb数据库中常用的保存形式。
我們先看一些caffe.proto中關於AnnotatedDatum的定義:
message AnnotatedDatum {
enum AnnotationType {
BBOX = 0;
}
optional Datum datum = 1;
// If there are "rich" annotations, specify the type of annotation.
// Currently it only supports bounding box.
// If there are no "rich" annotations, use label in datum instead.
optional AnnotationType type = 2;
// Each group contains annotation for a particular class.
repeated AnnotationGroup annotation_group = 3;
}
從中可以看出,AnnotatedDatum主要包含一個Datum結構、AnnotationType結構和一個AnnotationGroup結構。其中Datum是caffe官方自帶的結構體,用於保存image信息;AnnotationType用於指定label格式,枚舉AnnotationType已指定其為BBOX;AnnotationDroup則用於保存detection需要的box信息。以下分別查看這兩個(Datum和AnnotationGroup)結構的信息(同樣位於caffe.proto中):
Datum:
message Datum {
optional int32 channels = 1;
optional int32 height = 2;
optional int32 width = 3;
// 实际图像数据,以字节为单位
optional bytes data = 4;
optional int32 label = 5;
// (可选)基准面还可以保存浮点数据.
repeated float float_data = 6;
// 如果真实数据包含需要解码的编码图像
optional bool encoded = 7 [default = false];
}
主要參數為前五個,包括圖像的信息寬(width)、高(height)、通道數(channels),若為分類任務則label是代表該圖像是什麼類別,檢測任務則不用理會。
AnnotationGroup:
message AnnotationGroup {
optional int32 group_label = 1;
repeated Annotation annotation = 2;
}
可看出AnnotationGroup包含group_label和Annotation(repeated可重複)兩個結構,其中group_label為int型,用於指定該box group的類別,Annotation則保存box信息,接著看caffe.proto中定義的Annotation結構:
message Annotation {
optional int32 instance_id = 1 [default = 0];
optional NormalizedBBox bbox = 2;
}
其中包含instance_id和NomalizedBBox結構,instance_id存放該box的id索引,NormalizedBBox存放坐標信息,可繼續往下看NormalizedBBox結構:
message NormalizedBBox {
optional float xmin = 1;
optional float ymin = 2;
optional float xmax = 3;
optional float ymax = 4;
optional int32 label = 5;
optional bool difficult = 6;
optional float score = 7;
optional float size = 8;
}
可以看出該結構中包含有box信息(xmin,ymin,xmax,ymax)、該box的label類別(實際作用中沒有用到,上面的group_label為真實類別被應用)、是否為難例(difficult)、預測時用到的score值和box size。