cs231n / cs231n.github.io

Public facing notes page
MIT License
10.06k stars 4.06k forks source link

Spring 2022 GANs '_SingleProcessDataLoaderIter' object has no attribute 'next' #287

Open caojoshua opened 1 year ago

caojoshua commented 1 year ago

When extracting and showing MNIST, we get

'_SingleProcessDataLoaderIter' object has no attribute 'next'

According to this stackoverflow post, iter(...).next() is deprecated starting from pytorch 1.13, released in October 2022. I can fix this with this change:

     "    sampler=ChunkSampler(NUM_VAL, NUM_TRAIN)\n",
     ")\n",
     "\n",
-    "imgs = loader_train.__iter__().next()[0].view(batch_size, 784).numpy().squeeze()\n",
+    "i = loader_train.__iter__()\n",
+    "imgs = next(i)[0].view(batch_size, 784).numpy().squeeze()\n",
     "show_images(imgs)"
    ]
   },

(diff looks kinda weird for jupyter notebooks, but I think it gets the point across.)

caojoshua commented 1 year ago

As a side note, I think the code should be directly in the repo, rather than stored in zip files. That way users can easily submit PRs to fix code.

caojoshua commented 1 year ago

Same issue in Self Supervised Learning notebook in Data Augmentation blocks.

-    "    images, labels = dataiter.next()\n",
+    "    images, labels = next(dataiter)\n",