Skip to content

Commit

Permalink
iter.next() to next(iter)
Browse files Browse the repository at this point in the history
The new pytorch version does not allow the old command and causes the code to return errors when running. It is a small fix, that will especially help beginners.
  • Loading branch information
danblae committed Nov 14, 2022
1 parent e6dd99c commit 28e0e44
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions 09_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __len__(self):

# convert to an iterator and look at one random sample
dataiter = iter(train_loader)
data = dataiter.next()
data = next(dataiter)
features, labels = data
print(features, labels)

Expand Down Expand Up @@ -97,6 +97,6 @@ def __len__(self):

# look at one random sample
dataiter = iter(train_loader)
data = dataiter.next()
data = next(dataiter)
inputs, targets = data
print(inputs.shape, targets.shape)
2 changes: 1 addition & 1 deletion 13_feedforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
shuffle=False)

examples = iter(test_loader)
example_data, example_targets = examples.next()
example_data, example_targets = next(examples)

for i in range(6):
plt.subplot(2,3,i+1)
Expand Down
2 changes: 1 addition & 1 deletion 14_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def imshow(img):

# get some random training images
dataiter = iter(train_loader)
images, labels = dataiter.next()
images, labels = next(dataiter)

# show images
imshow(torchvision.utils.make_grid(images))
Expand Down
2 changes: 1 addition & 1 deletion 16_tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
shuffle=False)

examples = iter(test_loader)
example_data, example_targets = examples.next()
example_data, example_targets = next(examples)

for i in range(6):
plt.subplot(2,3,i+1)
Expand Down

0 comments on commit 28e0e44

Please sign in to comment.