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

Method __iter__

data/dataset_base.py:308–388  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

306 return data
307
308 def __iter__(self):
309 total_weights = sum(self.grouped_weights)
310 assert total_weights > 0.0
311 group_cumprobs = [sum(self.grouped_weights[:i + 1]) / total_weights
312 for i in range(len(self.grouped_weights))]
313 sequence_status = self.set_sequence_status()
314 batch_data_indexes = []
315
316 while True:
317 self.step_counter += 1
318 step_seed = self.base_and_epoch_seed + self.step_counter
319 step_rng = random.Random(step_seed)
320
321 random_image_num = int(step_rng.choices(
322 self.possible_nums,
323 weights=self.normalized_weights,
324 k=1
325 )[0])
326 random_aspect_ratio = round(
327 step_rng.uniform(self.aspect_ratio_range[0], self.aspect_ratio_range[1]),
328 2
329 )
330
331 # Ensure at least one sample from each group
332 if sequence_status['curr'] == 0:
333 for group_index, group_iter_names in enumerate(self.dataset_iters):
334 group_iter = group_iter_names[0]
335 group_name = group_iter_names[1]
336 group_dataset = group_iter_names[2]
337 if self.is_mandatory[group_index]: #grouped means recon group.
338 while True:
339 if group_name == "recon":
340 group_dataset.set_random_image_num(random_image_num)
341 group_dataset.set_random_aspect_ratio(random_aspect_ratio)
342 group_dataset.set_step_rng(step_seed)
343 sample = next(group_iter)
344 else:
345 sample = next(group_iter)
346
347 if sample is None:
348 continue
349 num_tokens = sample['num_tokens'] + 2 * len(sample['sequence_plan'])
350 if num_tokens < self.max_num_tokens_per_sample:
351 sequence_status = self.pack_sequence(sample, sequence_status)
352 batch_data_indexes.append(sample['data_indexes'])
353 break
354 else:
355 print(f"skip a sample with length {num_tokens}")
356 continue
357
358 n = random.random()
359 group_index = 0
360 for i, cumprob in enumerate(group_cumprobs):
361 if n < cumprob:
362 group_index = i
363 break
364 sample = next(self.dataset_iters[group_index][0])
365

Callers

nothing calls this directly

Calls 6

set_sequence_statusMethod · 0.95
pack_sequenceMethod · 0.95
to_tensorMethod · 0.95
set_random_image_numMethod · 0.45
set_step_rngMethod · 0.45

Tested by

no test coverage detected