我想知道如何处理我在数据加载器中的索引,每次训练时总是以相同的顺序。我想这样做是因为我的代码需要花费大量时间来保存验证集上结果的视觉输出,所以我决定只保存验证集上看到的 N 个第一个示例。
但是,当我在验证循环中传递所有批次时:
for t, (x, y, indices) in enumerate(dataset['loader_val'])
x = x.to(device=device, dtype=dtype) # move to device, e.g. GPU
y = y.to(device=device, dtype=dtype) # move to device, e.g. GPU
# Obtaining the scores ... -------------------------------------------------------------------
scores = model(x)
......
例如,我的值indices
在第一次迭代时并不总是相同的。我确信验证集的索引始终相同,因为我检查了 atdataset['loader_val'].sampler.indices
始终是相同的数组并以相同的方式排序。有没有办法enumerate()
以相同的方式始终采用内部索引dataset['loader_val']
?