original_docstring: 
          return ground truth image regions database
          :return: imdb[image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
          
docstring: return ground truth image regions database
docstring_tokens: return ground truth image regions database
code: def gt_roidb(self):
          """
          return ground truth image regions database
          :return: imdb[image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
          """
          cache_file = os.path.join(self.cache_path, self.name + '_gt_roidb.pkl')
          if os.path.exists(cache_file):
              with open(cache_file, 'rb') as fid:
                  roidb = cPickle.load(fid)
              print '{} gt roidb loaded from {}'.format(self.name, cache_file)
              self.num_images = len(roidb)
              self.roidb = roidb
              return roidb
  
  
  # <produce roidb ---------------------------------------------------------------
          with open(self.database_csv_fname,'r') as fid:
              database_csv = [x for x in fid.readlines()]
          roidb = []
          database_csv = np.unique(database_csv).tolist()
          for line in database_csv:
              line = line.strip()
              fields = line.split(',')
              if fields[1] not in self._class_to_ind.keys():
                  continue
  
              # im_idx=1 if self.dataset_type == 'poc' else 8
              # left_idx = 5 if self.dataset_type == 'poc' else 4
              # top_idx = 4 if self.dataset_type == 'poc' else 5
              # imw_idx = 12 if self.dataset_type == 'poc' else 9
              # imh_idx = 13 if self.dataset_type == 'poc' else 10
              im_idx= 8
              left_idx =  4
              top_idx =  5
              imw_idx =  9
              imh_idx = 10
  
              image_name = fields[im_idx]
              if len(self.image_list) > 0 and image_name not in self.image_list:
                  continue
              class_num = self._class_to_ind[fields[1]]
              class_name = fields[1]
              class_idx = class_num - 1
              left = int(fields[left_idx])
              top = int(fields[top_idx])
              width = int(fields[6])
              height = int(fields[7])
  
              if left <= 0:
                  left = 1
              right = left + width
              if top <= 0:
                  top = 1
              bottom = top + height
  
              img_width = int(fields[imw_idx])
              img_height = int(fields[imh_idx])
              if right>= img_width:
                  right = img_width - 1
              if bottom>= img_height:
                  bottom = img_height - 1
  
              # if self.dataset_type=='poc':
              #     image_name = fields[11]
              #     if len(self.image_list)>0 and image_name not in self.image_list:
              #         continue
              #     class_num = self._class_to_ind[fields[1]]
              #     class_name = fields[1]
              #     class_idx = class_num-1
              #     TLWH = np.array(fields[4:8]).astype(np.uint16)
              #     left = TLWH[1]
              #     if left<=0:
              #         left=1
              #     right = left+TLWH[2]
              #     top = TLWH[0]
              #     if top<=0:
              #         top=1
              #     bottom = top+TLWH[3]
              #
              #     img_width = int(fields[12])
              #     img_height = int(fields[13])
              #     if img_width>=right:
              #         right = img_width-1
              #     if img_height>=bottom:
              #         bottom = img_height-1
              #
              # if self.dataset_type == 'pilot':
              #     image_name = fields[8]
              #     if len(self.image_list)>0 and image_name not in self.image_list:
              #         continue
              #     class_num = self._class_to_ind[fields[1]]
              #     class_name = fields[1]
              #     class_idx = class_num - 1
              #     left = int(fields[4])
              #     top = int(fields[5])
              #     width = int(fields[6])
              #     height = int(fields[7])
              #
              #     if left<=0:
              #         left=1
              #     right = left + width
              #     if top<=0:
              #         top=1
              #     bottom = top + height
              #
              #     img_width = int(fields[9])
              #     img_height = int(fields[10])
              #     if img_width>=right:
              #         right = img_width-1
              #     if img_height>=bottom:
              #         bottom = img_height-1
  
              BBs = np.expand_dims([left, top, right, bottom],axis=0)
              oneHot = np.zeros((1, self.num_classes), dtype=np.float32)
              oneHot[0, class_idx] = 1
              img_path =  os.path.join(self.dataset_path, 'images', image_name)
              append = False
              for nImg, entry in enumerate(roidb):
                  if entry['image']==img_path:
                      append = True
                      append_idx = nImg
              if append:
                  roidb[append_idx]['boxes'] =np.concatenate((roidb[append_idx]['boxes'],BBs),axis=0)
                  roidb[append_idx]['gt_classes']+=[class_num]
                  roidb[append_idx]['gt_names']+=[class_name]
                  roidb[append_idx]['gt_overlaps'] = np.concatenate((roidb[append_idx]['gt_overlaps'],oneHot), axis=0)
                  continue
              #im = cv2.imread(img_path, cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION)
              roidb.append({
                  'boxes': BBs,
                  'flipped': False,
                  'gt_classes': [class_num],
                  'gt_names':[class_name],
                  'gt_overlaps': oneHot,
                  'width': int(img_width),
                  'height': int(img_height),
                  'image': img_path,
                  #'max_classes': class_num
                  #'max_overlaps': np.ones((BBs.shape[0], 1), dtype=np.float32),
                  #'aug_gen': aug_gen
              })
  
          for entry in roidb:
              entry['gt_classes'] = np.asarray(entry['gt_classes'])
              entry['max_classes'] = entry['gt_classes']
              entry['max_overlaps'] = np.ones((entry['boxes'].shape[0], 1), dtype=np.float32),
  
          self.num_images = len(roidb)
          self.roidb = roidb
  
          # >produce roidb ---------------------------------------------------------------
  
          # gt_roidb = []
          # for ii, index in enumerate(self.image_set_index):
          #     if (ii % 1000) == 0:
          #         print('Processing image {0} of {1}'.format(ii,len(self.image_set_index)))
          #     gt_roidb.append(self.load_imagenet_annotation(index))
          with open(cache_file, 'wb') as fid:
              cPickle.dump(self.roidb, fid, cPickle.HIGHEST_PROTOCOL) # gt_roidb
          print 'wrote gt roidb to {}'.format(cache_file)
          return self.roidb
code_tokens: def gt_roidb ( self ) : cache_file = os . path . join ( self . cache_path , self . name + '_gt_roidb.pkl' ) if os . path . exists ( cache_file ) : with open ( cache_file , 'rb' ) as fid : roidb = cPickle . load ( fid ) print '{} gt roidb loaded from {}' . format ( self . name , cache_file ) self . num_images = len ( roidb ) self . roidb = roidb return roidb with open ( self . database_csv_fname , 'r' ) as fid : database_csv = [ x for x in fid . readlines ( ) ] roidb = [ ] database_csv = np . unique ( database_csv ) . tolist ( ) for line in database_csv : line = line . strip ( ) fields = line . split ( ',' ) if fields [ 1 ] not in self . _class_to_ind . keys ( ) : continue im_idx = 8 left_idx = 4 top_idx = 5 imw_idx = 9 imh_idx = 10 image_name = fields [ im_idx ] if len ( self . image_list ) > 0 and image_name not in self . image_list : continue class_num = self . _class_to_ind [ fields [ 1 ] ] class_name = fields [ 1 ] class_idx = class_num - 1 left = int ( fields [ left_idx ] ) top = int ( fields [ top_idx ] ) width = int ( fields [ 6 ] ) height = int ( fields [ 7 ] ) if left <= 0 : left = 1 right = left + width if top <= 0 : top = 1 bottom = top + height img_width = int ( fields [ imw_idx ] ) img_height = int ( fields [ imh_idx ] ) if right >= img_width : right = img_width - 1 if bottom >= img_height : bottom = img_height - 1 BBs = np . expand_dims ( [ left , top , right , bottom ] , axis = 0 ) oneHot = np . zeros ( ( 1 , self . num_classes ) , dtype = np . float32 ) oneHot [ 0 , class_idx ] = 1 img_path = os . path . join ( self . dataset_path , 'images' , image_name ) append = False for nImg , entry in enumerate ( roidb ) : if entry [ 'image' ] == img_path : append = True append_idx = nImg if append : roidb [ append_idx ] [ 'boxes' ] = np . concatenate ( ( roidb [ append_idx ] [ 'boxes' ] , BBs ) , axis = 0 ) roidb [ append_idx ] [ 'gt_classes' ] += [ class_num ] roidb [ append_idx ] [ 'gt_names' ] += [ class_name ] roidb [ append_idx ] [ 'gt_overlaps' ] = np . concatenate ( ( roidb [ append_idx ] [ 'gt_overlaps' ] , oneHot ) , axis = 0 ) continue roidb . append ( { 'boxes' : BBs , 'flipped' : False , 'gt_classes' : [ class_num ] , 'gt_names' : [ class_name ] , 'gt_overlaps' : oneHot , 'width' : int ( img_width ) , 'height' : int ( img_height ) , 'image' : img_path , } ) for entry in roidb : entry [ 'gt_classes' ] = np . asarray ( entry [ 'gt_classes' ] ) entry [ 'max_classes' ] = entry [ 'gt_classes' ] entry [ 'max_overlaps' ] = np . ones ( ( entry [ 'boxes' ] . shape [ 0 ] , 1 ) , dtype = np . float32 ) , self . num_images = len ( roidb ) self . roidb = roidb with open ( cache_file , 'wb' ) as fid : cPickle . dump ( self . roidb , fid , cPickle . HIGHEST_PROTOCOL ) print 'wrote gt roidb to {}' . format ( cache_file ) return self . roidb
short_docstring: return ground truth image regions database
short_docstring_tokens: return ground truth image regions database
comment: """
          return ground truth image regions database
          :return: imdb[image_index]['boxes', 'gt_classes', 'gt_overlaps', 'flipped']
          """$SEP$# <produce roidb ---------------------------------------------------------------$SEP$# im_idx=1 if self.dataset_type == 'poc' else 8$SEP$# left_idx = 5 if self.dataset_type == 'poc' else 4$SEP$# top_idx = 4 if self.dataset_type == 'poc' else 5$SEP$# imw_idx = 12 if self.dataset_type == 'poc' else 9$SEP$# imh_idx = 13 if self.dataset_type == 'poc' else 10$SEP$# if self.dataset_type=='poc':$SEP$#     image_name = fields[11]$SEP$#     if len(self.image_list)>0 and image_name not in self.image_list:$SEP$#         continue$SEP$#     class_num = self._class_to_ind[fields[1]]$SEP$#     class_name = fields[1]$SEP$#     class_idx = class_num-1$SEP$#     TLWH = np.array(fields[4:8]).astype(np.uint16)$SEP$#     left = TLWH[1]$SEP$#     if left<=0:$SEP$#         left=1$SEP$#     right = left+TLWH[2]$SEP$#     top = TLWH[0]$SEP$#     if top<=0:$SEP$#         top=1$SEP$#     bottom = top+TLWH[3]$SEP$#$SEP$#     img_width = int(fields[12])$SEP$#     img_height = int(fields[13])$SEP$#     if img_width>=right:$SEP$#         right = img_width-1$SEP$#     if img_height>=bottom:$SEP$#         bottom = img_height-1$SEP$#$SEP$# if self.dataset_type == 'pilot':$SEP$#     image_name = fields[8]$SEP$#     if len(self.image_list)>0 and image_name not in self.image_list:$SEP$#         continue$SEP$#     class_num = self._class_to_ind[fields[1]]$SEP$#     class_name = fields[1]$SEP$#     class_idx = class_num - 1$SEP$#     left = int(fields[4])$SEP$#     top = int(fields[5])$SEP$#     width = int(fields[6])$SEP$#     height = int(fields[7])$SEP$#$SEP$#     if left<=0:$SEP$#         left=1$SEP$#     right = left + width$SEP$#     if top<=0:$SEP$#         top=1$SEP$#     bottom = top + height$SEP$#$SEP$#     img_width = int(fields[9])$SEP$#     img_height = int(fields[10])$SEP$#     if img_width>=right:$SEP$#         right = img_width-1$SEP$#     if img_height>=bottom:$SEP$#         bottom = img_height-1$SEP$#im = cv2.imread(img_path, cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION)$SEP$#'max_classes': class_num$SEP$#'max_overlaps': np.ones((BBs.shape[0], 1), dtype=np.float32),$SEP$#'aug_gen': aug_gen$SEP$# >produce roidb ---------------------------------------------------------------$SEP$# gt_roidb = []$SEP$# for ii, index in enumerate(self.image_set_index):$SEP$#     if (ii % 1000) == 0:$SEP$#         print('Processing image {0} of {1}'.format(ii,len(self.image_set_index)))$SEP$#     gt_roidb.append(self.load_imagenet_annotation(index))$SEP$# gt_roidb