MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / group_by_bucket

Method group_by_bucket

datasets/sampler.py:213–239  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

211 return self.get_num_batch() // dist.get_world_size()
212
213 def group_by_bucket(self) -> dict:
214 bucket_sample_dict = OrderedDict()
215
216 from pandarallel import pandarallel
217
218 pandarallel.initialize(
219 nb_workers=self.num_bucket_build_workers, progress_bar=False)
220 get_logger().info('Building buckets...')
221 bucket_ids = self.dataset.data.parallel_apply(
222 apply,
223 axis=1,
224 method=self.bucket.get_bucket_id,
225 frame_interval=self.dataset.frame_interval,
226 seed=self.seed + self.epoch,
227 num_bucket=self.bucket.num_bucket,
228 )
229
230 # group by bucket
231 # each data sample is put into a bucket with a similar image/video size
232 for i in range(len(self.dataset)):
233 bucket_id = bucket_ids[i]
234 if bucket_id is None:
235 continue
236 if bucket_id not in bucket_sample_dict:
237 bucket_sample_dict[bucket_id] = []
238 bucket_sample_dict[bucket_id].append(i)
239 return bucket_sample_dict
240
241 def get_num_batch(self) -> int:
242 bucket_sample_dict = self.group_by_bucket()

Callers 2

__iter__Method · 0.95
get_num_batchMethod · 0.95

Calls 1

get_loggerFunction · 0.90

Tested by

no test coverage detected