Update:
建议先看从编程实现角度学习Faster R-CNN,比较直观。这里由于源代码抽象程度较高,显得比较混乱。
Old:
之前看过检测api整体的代码架构,rpn部分和几个基本类,这次仔细看看Fast r-cnn部分,顺便把之前看过的东西串一串。
"""object_detection/meta_architectures/faster_rcnn_meta_arch.py"""
class FasterRCNNFeatureExtractor(object)类声明了_extract_proposal_features和_extract_box_classifier_features等抽象函数。
不过我们先看下restore_from_classification_checkpoint_fn函数,它返回的是variables_to_restore字典,看一下后面的restore_map函数就懂了,创建了模型中变量和checkpoint中变量名字的映射,且区分了分类的checkpoint(用于初始化)和检测的checkpoint。
class FasterRCNNMetaArch(model.DetectionModel)
注意到用了好多@property,是将方法当成属性来调用。在类的定义中使用@property修饰函数,可以让调用者写出简短的代码,同时保证对参数进行必要的检查。还可以定义只读属性,不定义setter方法就是一个只读属性。
"""这个max_num_proposals为什么这样设定?,暂时不太明白,后续研究"""
def max_num_proposals(self):
Max number of proposals (to pad to) for each image in the input batch.
At training time, this is set to be the `second_stage_batch_size` if hard
example miner is not configured, else it is set to
`first_stage_max_proposals`. At inference time, this is always set to
`first_stage_max_proposals`.
"""这个函数调用了image_resizer_fn,把归一化等其他预处理都留给feature_extractor来做"""
def preprocess(self, inputs)