MCPcopy Create free account
hub / github.com/LetheSec/PLG-MI-Attack / sample_random_batch

Function sample_random_batch

baselines/utils.py:295–311  ·  view source on GitHub ↗

* inputs: - dataset (torch.utils.data.Dataset, required) An instance of torch.utils.data.Dataset. - batch_size (int, optional) Batch size. * returns: A mini-batch randomly sampled from the input dataset.

(dataset, batch_size=32)

Source from the content-addressed store, hash-verified

293
294
295def sample_random_batch(dataset, batch_size=32):
296 """
297 * inputs:
298 - dataset (torch.utils.data.Dataset, required)
299 An instance of torch.utils.data.Dataset.
300 - batch_size (int, optional)
301 Batch size.
302 * returns:
303 A mini-batch randomly sampled from the input dataset.
304 """
305 num_samples = len(dataset)
306 batch = []
307 for _ in range(min(batch_size, num_samples)):
308 index = random.choice(range(0, num_samples))
309 x = torch.unsqueeze(dataset[index], dim=0)
310 batch.append(x)
311 return torch.cat(batch, dim=0)
312
313
314def get_deprocessor():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected