def iter(self):
data_idxs = np.arange(len(self.data_source))
if self.shuffle:
np.random.shuffle(data_idxs)
for idx in data_idxs:
yield idx
if name == 'main':
x = [1, 2, 3]
sampler = Sampler(x, shuffle=True)
p = 0
for xx in sampler:
print(x[xx])
p += 1
if p == 10: break
I'm not sure about the function of this code. I wonder if you could tell me,thank you.
! /usr/bin/env python
-- coding: utf-8 --
#
Copyright © 2017 bily Huazhong University of Science and Technology
#
Distributed under terms of the MIT license.
"""Dataset Sampler"""
from future import absolute_import from future import division from future import print_function
import numpy as np
class Sampler(object): def init(self, data_source, shuffle=True): self.data_source = data_source self.shuffle = shuffle
def iter(self): data_idxs = np.arange(len(self.data_source)) if self.shuffle: np.random.shuffle(data_idxs)
if name == 'main': x = [1, 2, 3] sampler = Sampler(x, shuffle=True) p = 0 for xx in sampler: print(x[xx]) p += 1 if p == 10: break I'm not sure about the function of this code. I wonder if you could tell me,thank you.