Closed ericjang closed 2 years ago
Hello,
It is not a bug. FFCV produces arrays and give them to you as you iterate through the iterator. However they are owned by FFCV, therefore, once an iteration is finished FFCV might (to avoid allocating too much memory) reuse a tensor and write something else there. If you need data after an iteration is over it's your responsibility to allocate memory and copy it there within the loop. As a general rule. If you didn't create an array you don't own it and therefore shouldn't assume the owner (here FFCV) will not use it for other purposes.
TLDR: Adding a copy()
lines 58 and 79 will fix the "issue".
Hope this helps!
This commit adds a test that demonstrates the issue - let me know if I should open a PR to check this in. https://github.com/libffcv/ffcv/commit/655c7f8f7963343a2d6482c371ef78a4c5df58d6
Basically there are two tests that write images paired with a dummy label (either as an NDArrayField or an IntField). Then I read them back. The set of labels read no longer match the expected labels written.
for example, on the integers: