original_docstring: Enrich the imdb's roidb by adding some derived quantities that
    are useful for training. This function precomputes the maximum
    overlap, taken over ground-truth boxes, between each ROI and
    each ground-truth box. The class with maximum overlap is also
    recorded.
    
docstring: Enrich the imdb's roidb by adding some derived quantities that
  are useful for training. This function precomputes the maximum
  overlap, taken over ground-truth boxes, between each ROI and
  each ground-truth box. The class with maximum overlap is also
  recorded.
docstring_tokens: Enrich the imdb ' s roidb by adding some derived quantities that are useful for training . This function precomputes the maximum overlap taken over ground - truth boxes between each ROI and each ground - truth box . The class with maximum overlap is also recorded .
code: def prepare_roidb(imdb):
    """Enrich the imdb's roidb by adding some derived quantities that
    are useful for training. This function precomputes the maximum
    overlap, taken over ground-truth boxes, between each ROI and
    each ground-truth box. The class with maximum overlap is also
    recorded.
    """
    roidb = imdb.roidb
    if not (imdb.name.startswith('vg') or imdb.name.startswith('avg') or imdb.name.startswith('coco')):
      sizes = [PIL.Image.open(imdb.image_path_at(i)).size
           for i in range(imdb.num_images)]
    
    print('image_index has length {} when preparing training data (func prepare_roidb)'.format(len(imdb.image_index)))
    counter = 0
    for i in range(len(imdb.image_index)):
      roidb[i]['image'] = imdb.image_path_at(i)
      if not (imdb.name.startswith('vg') or imdb.name.startswith('avg') or imdb.name.startswith('coco')):
        roidb[i]['width'] = sizes[i][0]
        roidb[i]['height'] = sizes[i][1]
      # need gt_overlaps as a dense array for argmax
      gt_overlaps = roidb[i]['gt_overlaps'].toarray()
      # max overlap with gt over classes (columns)
      max_overlaps = gt_overlaps.max(axis=1)
      # gt class that had the max overlap
      max_classes = gt_overlaps.argmax(axis=1)
      roidb[i]['max_classes'] = max_classes
      roidb[i]['max_overlaps'] = max_overlaps
      # sanity checks
      # max overlap of 0 => class should be zero (background)
      zero_inds = np.where(max_overlaps == 0)[0]
      assert all(max_classes[zero_inds] == 0)
      # max overlap > 0 => class should not be zero (must be a fg class)
      nonzero_inds = np.where(max_overlaps > 0)[0]
      assert all(max_classes[nonzero_inds] != 0)
  
      counter += 1
      if counter % 100 == 0:
        sys.stdout.write(".")
        if counter % 5000 == 0:
          sys.stdout.write(str(counter/1000)+'k')
          sys.stdout.write("\n")
        sys.stdout.flush()
    sys.stdout.write("\n")
    sys.stdout.flush()
code_tokens: def prepare_roidb ( imdb ) : roidb = imdb . roidb if not ( imdb . name . startswith ( 'vg' ) or imdb . name . startswith ( 'avg' ) or imdb . name . startswith ( 'coco' ) ) : sizes = [ PIL . Image . open ( imdb . image_path_at ( i ) ) . size for i in range ( imdb . num_images ) ] print ( 'image_index has length {} when preparing training data (func prepare_roidb)' . format ( len ( imdb . image_index ) ) ) counter = 0 for i in range ( len ( imdb . image_index ) ) : roidb [ i ] [ 'image' ] = imdb . image_path_at ( i ) if not ( imdb . name . startswith ( 'vg' ) or imdb . name . startswith ( 'avg' ) or imdb . name . startswith ( 'coco' ) ) : roidb [ i ] [ 'width' ] = sizes [ i ] [ 0 ] roidb [ i ] [ 'height' ] = sizes [ i ] [ 1 ] gt_overlaps = roidb [ i ] [ 'gt_overlaps' ] . toarray ( ) max_overlaps = gt_overlaps . max ( axis = 1 ) max_classes = gt_overlaps . argmax ( axis = 1 ) roidb [ i ] [ 'max_classes' ] = max_classes roidb [ i ] [ 'max_overlaps' ] = max_overlaps zero_inds = np . where ( max_overlaps == 0 ) [ 0 ] assert all ( max_classes [ zero_inds ] == 0 ) nonzero_inds = np . where ( max_overlaps > 0 ) [ 0 ] assert all ( max_classes [ nonzero_inds ] != 0 ) counter += 1 if counter % 100 == 0 : sys . stdout . write ( "." ) if counter % 5000 == 0 : sys . stdout . write ( str ( counter / 1000 ) + 'k' ) sys . stdout . write ( "\n" ) sys . stdout . flush ( ) sys . stdout . write ( "\n" ) sys . stdout . flush ( )
short_docstring: Enrich the imdb's roidb by adding some derived quantities that
  are useful for training.
short_docstring_tokens: Enrich the imdb ' s roidb by adding some derived quantities that are useful for training .
comment: """Enrich the imdb's roidb by adding some derived quantities that
    are useful for training. This function precomputes the maximum
    overlap, taken over ground-truth boxes, between each ROI and
    each ground-truth box. The class with maximum overlap is also
    recorded.
    """$SEP$# need gt_overlaps as a dense array for argmax$SEP$# max overlap with gt over classes (columns)$SEP$# gt class that had the max overlap$SEP$# sanity checks$SEP$# max overlap of 0 => class should be zero (background)$SEP$# max overlap > 0 => class should not be zero (must be a fg class)