diff --git a/python/oneflow/utils/data/sampler.py b/python/oneflow/utils/data/sampler.py index 7ff1915f00d..7a53b813d4d 100644 --- a/python/oneflow/utils/data/sampler.py +++ b/python/oneflow/utils/data/sampler.py @@ -141,34 +141,24 @@ def __iter__(self): n = len(self.data_source) if self.generator is None: generator = flow.Generator() - generator.manual_seed( - # TODO: replace with flow.randint - flow.Tensor(1, dtype=flow.int64) - .uniform_(0, 999) - .numpy() - .item() - ) + generator.manual_seed(np.random.randint(0, np.iinfo(np.int64).max)) + # TODO: use Tensor.random_ + # generator.manual_seed( + # int(flow.empty((), dtype=flow.int64).random_().item()) + # ) else: generator = self.generator if self.replacement: - np.random.randint() for _ in range(self.num_samples // 32): - yield from np.random.randint( - high=n, size=(32,), dtype=np.int64 + yield from flow.randint( + high=n, size=(32,), dtype=flow.int64, generator=generator ).tolist() - # TODO: use flow.randint replace np.randint - # yield from flow.randint( - # high=n, size=(32,), dtype=flow.int64, generator=generator - # ).tolist() - yield from np.random.randint( - high=n, size=(self.num_samples % 32,), dtype=np.int64 + yield from flow.randint( + high=n, + size=(self.num_samples % 32,), + dtype=flow.int64, + generator=generator, ).tolist() - # yield from flow.randint( - # high=n, - # size=(self.num_samples % 32,), - # dtype=flow.int64, - # generator=generator, - # ).tolist() else: yield from flow.randperm(n, generator=generator).tolist() diff --git a/python/oneflow/utils/vision/transforms/transforms.py b/python/oneflow/utils/vision/transforms/transforms.py index b2def901ab7..f5320272dc3 100644 --- a/python/oneflow/utils/vision/transforms/transforms.py +++ b/python/oneflow/utils/vision/transforms/transforms.py @@ -586,11 +586,8 @@ def get_params( if w == tw and h == th: return 0, 0, h, w - # TODO:replace with flow.randint - # i = flow.randint(0, h - th + 1, size=(1, )).item() - # j = flow.randint(0, w - tw + 1, size=(1, )).item() - i = np.random.randint(low=0, high=h - th + 1, size=(1,), dtype=np.int32) - j = np.random.randint(low=0, high=w - tw + 1, size=(1,), dtype=np.int32) + i = flow.randint(0, h - th + 1, size=(1,)).item() + j = flow.randint(0, w - tw + 1, size=(1,)).item() return i, j, th, tw def __init__( @@ -788,15 +785,8 @@ def get_params( h = int(round(math.sqrt(target_area / aspect_ratio))) if 0 < w <= width and 0 < h <= height: - # TODO:replace with flow.randint - # i = flow.randint(0, height - h + 1, size=(1,)).item() - # j = flow.randint(0, width - w + 1, size=(1,)).item() - i = np.random.randint( - low=0, high=height - h + 1, size=(1,), dtype=np.int32 - ) - j = np.random.randint( - low=0, high=width - w + 1, size=(1,), dtype=np.int32 - ) + i = flow.randint(0, height - h + 1, size=(1,)).item() + j = flow.randint(0, width - w + 1, size=(1,)).item() return i, j, h, w # Fallback to central crop