original_docstring: Load object features from tsv file.
      :param fname: The path to the tsv file.
      :param topk: Only load features for top K images (lines) in the tsv file.
          Will load all the features if topk is either -1 or None.
      :return: A list of image object features where each feature is a dict.
          See FILENAMES above for the keys in the feature dict.
      
docstring: Load object features from tsv file.
docstring_tokens: Load object features from tsv file .
code: def load_obj_tsv(fname, ids, topk=args.topk):
      """Load object features from tsv file.
      :param fname: The path to the tsv file.
      :param topk: Only load features for top K images (lines) in the tsv file.
          Will load all the features if topk is either -1 or None.
      :return: A list of image object features where each feature is a dict.
          See FILENAMES above for the keys in the feature dict.
      """
      data = []
      start_time = time.time()
      print("Start to load Faster-RCNN detected objects from %s" % fname)
      with open(fname) as f:
          reader = csv.DictReader(f, FIELDNAMES, delimiter="\t")
          boxes = args.num_features # Same boxes for all
  
          for i, item in enumerate(reader):
              
              # Check if id in list of ids to save memory
              if int(item["img_id"]) not in ids:
                  continue
  
              for key in ['img_h', 'img_w', 'num_boxes']:
                  item[key] = int(item[key])
              
              boxes = item['num_boxes']
              decode_config = [
                  ('objects_id', (boxes, ), np.int64),
                  ('objects_conf', (boxes, ), np.float32),
                  ('attrs_id', (boxes, ), np.int64),
                  ('attrs_conf', (boxes, ), np.float32),
                  ('boxes', (boxes, 4), np.float32),
                  ('features', (boxes, -1), np.float32),
              ]
              for key, shape, dtype in decode_config:
                  item[key] = np.frombuffer(base64.b64decode(item[key]), dtype=dtype)
                  try:
                      item[key] = item[key].reshape(shape)
                  except:
                      # In 1 out of 10K cases, the shape comes out wrong; We make necessary adjustments
                      shape = list(shape)
                      shape[0] += 1
                      shape = tuple(shape)
                      item[key] = item[key].reshape(shape)  
   
                  item[key].setflags(write=False)
                      
              data.append(item)
              if topk is not None and len(data) == topk:
                  break
      elapsed_time = time.time() - start_time
      print("Loaded %d images in file %s in %d seconds." % (len(data), fname, elapsed_time))
      return data
code_tokens: def load_obj_tsv ( fname , ids , topk = args . topk ) : data = [ ] start_time = time . time ( ) print ( "Start to load Faster-RCNN detected objects from %s" % fname ) with open ( fname ) as f : reader = csv . DictReader ( f , FIELDNAMES , delimiter = "\t" ) boxes = args . num_features for i , item in enumerate ( reader ) : if int ( item [ "img_id" ] ) not in ids : continue for key in [ 'img_h' , 'img_w' , 'num_boxes' ] : item [ key ] = int ( item [ key ] ) boxes = item [ 'num_boxes' ] decode_config = [ ( 'objects_id' , ( boxes , ) , np . int64 ) , ( 'objects_conf' , ( boxes , ) , np . float32 ) , ( 'attrs_id' , ( boxes , ) , np . int64 ) , ( 'attrs_conf' , ( boxes , ) , np . float32 ) , ( 'boxes' , ( boxes , 4 ) , np . float32 ) , ( 'features' , ( boxes , - 1 ) , np . float32 ) , ] for key , shape , dtype in decode_config : item [ key ] = np . frombuffer ( base64 . b64decode ( item [ key ] ) , dtype = dtype ) try : item [ key ] = item [ key ] . reshape ( shape ) except : shape = list ( shape ) shape [ 0 ] += 1 shape = tuple ( shape ) item [ key ] = item [ key ] . reshape ( shape ) item [ key ] . setflags ( write = False ) data . append ( item ) if topk is not None and len ( data ) == topk : break elapsed_time = time . time ( ) - start_time print ( "Loaded %d images in file %s in %d seconds." % ( len ( data ) , fname , elapsed_time ) ) return data
short_docstring: Load object features from tsv file.
short_docstring_tokens: Load object features from tsv file .
comment: """Load object features from tsv file.
      :param fname: The path to the tsv file.
      :param topk: Only load features for top K images (lines) in the tsv file.
          Will load all the features if topk is either -1 or None.
      :return: A list of image object features where each feature is a dict.
          See FILENAMES above for the keys in the feature dict.
      """$SEP$# Same boxes for all$SEP$# Check if id in list of ids to save memory$SEP$# In 1 out of 10K cases, the shape comes out wrong; We make necessary adjustments