sampler_train = torch.utils.data.RandomSampler(torch.arange(10))
for i in sampler_train:
print(i)
print('=================')
for k in sampler_train:
print(k)
print('--------------')
sampler_val = torch.utils.data.SequentialSampler(torch.arange(10))
for j in sampler_val:
print(j)
print('=================')
for l in sampler_val:
print(l)
# 从结果上可以看出来RandomSampler随机采样在使用的时候,每次调用输出的
# 顺序都不大一样。而SequentialSampler顺序采样,每次结果都一样
输出结果:
3
0
1
6
4
5
9
7
8
2
=================
5
9
6
0
3
4
1
7
8
2
--------------
0
1
2
3
4
5
6
7
8
9
=================
0
1
2
3
4
5
6
7
8
9