Tensorflow version Faster RCNN source parsing (TFFRCNN) (9) roi_data_layer / layer.py

This blog is on github CharlesShang / TFFRCNN version of the source code for parsing Series Notes

--------------- personal study notes ---------------

---------------- The author Wu Jiang --------------

------ Click here to link to the original blog Park ------

 

The script defines a RoIDataLayer class, the class defines the following functions:

class RoIDataLayer(object):
    """Fast R-CNN data layer used for training."""

Constructor 1 .__ init __ (self, roidb, num_classes) class

RoIDataLayer performed automatically instantiates object class and calls _shuffle_roidb_inds (...) function generates self._perm and self._cur

    DEF  __init__ (Self, roidb, num_classes):
         "" " . roidb to the Set at The BE Used by the this Layer During Training " "" 
        self._roidb = roidb 
        self._num_classes = num_classes
         # get self._perm (as 0 --- len array) and a set self._cur (self._roidb) composed of scrambled 0 = 
        self._shuffle_roidb_inds ()

2._shuffle_roidb_inds (self) obtained for all index order disrupted roidb image formed self._perm, the self._cur set to 0, retrieves (minibatch.py in roidb index starting index position), it is _get_next_minibatch_inds (. ..)transfer

    DEF _shuffle_roidb_inds (Self):
         "" " . Randomly permute permutation Training roidb The " "" 
        # np.random.permutation () function is disrupted order of the array 
        # roidb random order 
        self._perm = np.random.permutation (np.arange (len (self._roidb)))
         # start flag minibatch_rois index 
        self._cur = 0

3._get_next_minibatch_inds (self) Gets the next mini_batch in roidb index consisting of all roidb image and return, is _get_next_minibatch (...) call

When using the default RPN each minibatch use two image? But minibatch.py ​​seen only allow single batch single image?

    # Get the next mini_batch in roidb index 
    DEF _get_next_minibatch_inds (Self):
         "" " the Return at The roidb at The indices for the Next minibatch. " "" 
        # Default = True TRAIN.HAS_RPN 
        IF cfg.TRAIN.HAS_RPN:
             # default use each RPN a minibatch use two image? ? ? But minibatch.py seen only allow single batch single image? ? ? 
            # Default = 2 TRAIN.IMS_PER_BATCH (Images to use per minibatch) 
            # The self._cur set 0, self._perm out of sequence, the next round (roidb all iterations counted as an image) 
            IF self._cur CFG + .TRAIN.IMS_PER_BATCH> = len (self._roidb): 
                self._shuffle_roidb_inds () 
            # default each taking two images roidb (index), roidb is the configuration of the corresponding minibatch.py roidb
            db_inds = self._perm[self._cur:self._cur + cfg.TRAIN.IMS_PER_BATCH]
            # 更新self._cur
            self._cur += cfg.TRAIN.IMS_PER_BATCH
# 若不使用RPN
else: # sample images db_inds = np.zeros((cfg.TRAIN.IMS_PER_BATCH), dtype=np.int32) i = 0 while (i < cfg.TRAIN.IMS_PER_BATCH): ind = self._perm[self._cur] num_objs = self._roidb[ind]['boxes'].shape[0] if= num_objs! 0: db_inds [I] = IND I + =. 1 self._cur + =. 1 IF self._cur> = len (self._roidb): # The self._cur set 0, self._perm out of sequence, for The next round (all images roidb iterations counted as one) training self._shuffle_roidb_inds () return db_inds

4._get_next_minibatch(self)

Get the next mini_batch roidb (rois information shall minibatch.py in roidb, part of the image), call _get_next_minibatch_inds () Get the next index mini_batch in roidb ---> Get minibatch_db (i.e. minibatch.py in roidb ) when ---> as a parameter to minibatch_db (minibatch_db, self._num_classes) blobs at strategically configured network input (RPN call using default training phase get_minibatch, blob containing 'data', 'gt_boxes', ' gt_ishard ',' dontcare_area ',' im_info ',' im_name 'field), are forward (...) call

    DEF _get_next_minibatch (Self):
         "" " 
        . the Return to BE at The blobs at The Used for the Next minibatch 
        the If cfg.TRAIN.USE_PREFETCH IS True, in the then blobs computed by Will BE A 
        separate Process and Made the Available through self._blob_queue. 
        " "" 
        db_inds = self._get_next_minibatch_inds ()
         # minibatch_db shall minibatch.py in roidb, as a list, each element containing an image-related information rois 
        minibatch_db = [self._roidb [I] for I in db_inds]
         # (call minibatch in .py get_minibatch (...)) of the input network configuration of blobs at strategically 
        return get_minibatch (minibatch_db, self._num_classes)

5.forward(self)

Call _get_next_minibatch () and get blobs return, no calls

    def forward(self):
        """Get blobs and copy them into this layer's top blob vector."""
        # 获取网络输入的blobs
        blobs = self._get_next_minibatch()
        return blobs

Guess you like

Origin www.cnblogs.com/deeplearning1314/p/11314595.html