MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / get_nearby_ids

Method get_nearby_ids

data/recon_dataset.py:307–375  ·  view source on GitHub ↗

TODO: add the function to sample the ids by pose similarity ranking. Sample a set of IDs from a sequence close to a given start index. You can specify the range either as a ratio of the number of input IDs or as a fixed integer window. Args: i

(self, ids, full_seq_num, expand_ratio=None, expand_range=None, rng=None)

Source from the content-addressed store, hash-verified

305
306
307 def get_nearby_ids(self, ids, full_seq_num, expand_ratio=None, expand_range=None, rng=None):
308 """
309 TODO: add the function to sample the ids by pose similarity ranking.
310
311 Sample a set of IDs from a sequence close to a given start index.
312
313 You can specify the range either as a ratio of the number of input IDs
314 or as a fixed integer window.
315
316
317 Args:
318 ids (list): Initial list of IDs. The first element is used as the anchor.
319 full_seq_num (int): Total number of items in the full sequence.
320 expand_ratio (float, optional): Factor by which the number of IDs expands
321 around the start index. Default is 2.0 if neither expand_ratio nor
322 expand_range is provided.
323 expand_range (int, optional): Fixed number of items to expand around the
324 start index. If provided, expand_ratio is ignored.
325
326 Returns:
327 numpy.ndarray: Array of sampled IDs, with the first element being the
328 original start index.
329
330 Examples:
331 # Using expand_ratio (default behavior)
332 # If ids=[100,101,102] and full_seq_num=200, with expand_ratio=2.0,
333 # expand_range = int(3 * 2.0) = 6, so IDs sampled from [94...106] (if boundaries allow).
334
335 # Using expand_range directly
336 # If ids=[100,101,102] and full_seq_num=200, with expand_range=10,
337 # IDs are sampled from [90...110] (if boundaries allow).
338
339 Raises:
340 ValueError: If no IDs are provided.
341 """
342 if len(ids) == 0:
343 raise ValueError("No IDs provided.")
344 if expand_ratio == -1:
345 return ids
346
347 if expand_range is None and expand_ratio is None:
348 expand_ratio = 2.0 # Default behavior
349
350 total_ids = len(ids)
351 start_idx = ids[0]
352
353 # Determine the actual expand_range
354 if expand_range is None:
355 # Use ratio to determine range
356 expand_range = int(total_ids * expand_ratio)
357
358 # Calculate valid boundaries
359 low_bound = max(0, start_idx - expand_range)
360 high_bound = min(full_seq_num, start_idx + expand_range)
361
362 # Create the valid range of indices
363 valid_range = np.arange(low_bound, high_bound)
364

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected