object_detectionAPI源码阅读笔记(5-mode

2018-10-06  本文已影响240人  yanghedada

model.py

上一篇说到Faster R-CNN的流程图被写成类,这里就介绍目标检测的基类-----DetectionModel。在model.py里面,DetectionModel定义的很简单。

概述:

检测模型的流程图:
Training time:
inputs (images tensor) -> preprocess -> predict -> loss -> outputs (loss tensor)

Evaluation time:
inputs (images tensor) -> preprocess -> predict -> postprocess -> outputs (boxes tensor, scores tensor, classes tensor, num_detections tensor)

DetectionModel(object)

就是下面的这些:有好几个未实现的算法:

class DetectionModel(object):
  """Abstract base class for detection models."""
  __metaclass__ = ABCMeta

  def __init__(self, num_classes):
    self._num_classes = num_classes
    self._groundtruth_lists = {}

  @property
  def num_classes(self):
    return self._num_classes

  def groundtruth_lists(self, field):
    return field in self._groundtruth_lists

  @abstractmethod
  def preprocess(self, inputs):
    pass

  @abstractmethod
  def predict(self, preprocessed_inputs):
    pass

  @abstractmethod
  def postprocess(self, prediction_dict, **params):
    pass

  @abstractmethod
  def loss(self, prediction_dict):
    pass

  def provide_groundtruth(self,
                          groundtruth_boxes_list,
                          groundtruth_classes_list,
                          groundtruth_masks_list=None,
                          groundtruth_keypoints_list=None):
    self._groundtruth_lists[fields.BoxListFields.boxes] = groundtruth_boxes_list
    self._groundtruth_lists[
        fields.BoxListFields.classes] = groundtruth_classes_list
    if groundtruth_masks_list:
      self._groundtruth_lists[
          fields.BoxListFields.masks] = groundtruth_masks_list
    if groundtruth_keypoints_list:
      self._groundtruth_lists[
          fields.BoxListFields.keypoints] = groundtruth_keypoints_list

  @abstractmethod
  def restore_map(self, from_detection_checkpoint=True):
    pass

介绍几个重要的函数

这个DetectionModel是所有检测模型的抽象基类,实现需要在各个子类实现,在object_detection\meta_architectures的所有类的定义都是在DetectionModel上定义的,下一篇就是开挖faster_rcnn_meta_arch.py。

DetectionModel使用流程

请看object_detectionAPI源码阅读笔记(3)

参考:

TensorFlow Object Detection API 源码(1) DetectionModel

上一篇 下一篇

猜你喜欢

热点阅读