在之前的博文中介绍过用tf提供的预训练模型进行inference,非常简单。这里我们深入源码,了解检测API的代码架构,每个部分的深入阅读留待后续。
首先官方文档还是比较丰富的,可以先全看一遍,然后和核心的模型有关的文档是:
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/defining_your_own_model.md
还有一个比较麻烦的地方是这里使用protobuf文件来管理参数配置,参见:
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/configuring_jobs.md
'''构建自己模型的接口是虚基类DetectionModel,具体有5个抽象函数需要实现。
'''
object_detection/core/model.py
def groundtruth_lists(self, field):
"""Access list of groundtruth tensors."""
def groundtruth_has_field(self, field):
"""Determines whether the groundtruth includes the given field."""
def provide_groundtruth(self,
groundtruth_boxes_list,
groundtruth_classes_list,
groundtruth_masks_list=None,
groundtruth_keypoints_list=None):
"""Provide groundtruth tensors."""
@abstractmethod
def preprocess(self, inputs):
@abstractmethod
def predict(self, preprocessed_inputs)
@abstractmethod
def postprocess(self, prediction_dict, **params)