Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main.py failed #236

Open
ggghamd opened this issue Oct 3, 2021 · 2 comments
Open

main.py failed #236

ggghamd opened this issue Oct 3, 2021 · 2 comments

Comments

@ggghamd
Copy link

ggghamd commented Oct 3, 2021

https://github.com/yunjey/pytorch-tutorial/blob/master/tutorials/01-basics/pytorch_basics/main.py:

root@sriov-guest:~/dev-learn/gpu/pytorch/tutorial# python3 pytorch-main.py
tensor(2.)
tensor(1.)
tensor(1.)
w:  Parameter containing:
tensor([[-0.4404, -0.1190,  0.4829],
        [ 0.4956, -0.3760,  0.1435]], requires_grad=True)
b:  Parameter containing:
tensor([0.4760, 0.5684], requires_grad=True)
loss:  1.0722367763519287
dL/dw:  tensor([[-0.4775,  0.0949,  0.0065],
        [ 0.0698, -0.4295, -0.0664]])
dL/db:  tensor([0.3632, 0.3266])
loss after 1 step optimization:  1.0655767917633057
Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ../../data/cifar-10-python.tar.gz
170499072it [00:32, 5230791.96it/s]
Extracting ../../data/cifar-10-python.tar.gz to ../../data/
torch.Size([3, 32, 32])
6
Traceback (most recent call last):
  File "pytorch-main.py", line 157, in <module>
    shuffle=True)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 270, in __init__
    sampler = RandomSampler(dataset, generator=generator)  # type: ignore[arg-type]
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/sampler.py", line 103, in __init__
    "value, but got num_samples={}".format(self.num_samples))
ValueError: num_samples should be a positive integer value, but got num_samples=0
root@sriov-guest:~/dev-learn/gpu/pytorch/tutorial#

@rollysys
Copy link

The main.py is not a complete example code, it's some code snippets.
You shoud implement your own "custom data loader", refer to torchvision.datasets.CIFAR10.
Your error is caused by null implementation of CustomDataset.

@lsnnt
Copy link

lsnnt commented Mar 7, 2024

nnt@mycomp:~/pytorch-tutorial/tutorials/01-basics/pytorch_basics$ python3 main.py 
tensor(2.)
tensor(1.)
tensor(1.)
w:  Parameter containing:
tensor([[-0.0246,  0.4567, -0.4118],
        [ 0.1679, -0.5086, -0.3876]], requires_grad=True)
b:  Parameter containing:
tensor([0.0529, 0.2922], requires_grad=True)
loss:  1.949414610862732
dL/dw:  tensor([[-0.7870,  1.5242, -0.0795],
        [ 0.8206, -0.9073, -0.7711]])
dL/db:  tensor([-0.5564,  0.0907])
loss after 1 step optimization:  1.896445631980896
Files already downloaded and verified
torch.Size([3, 32, 32])
6
Traceback (most recent call last):
  File "/home/nnt/pytorch-tutorial/tutorials/01-basics/pytorch_basics/main.py", line 124, in <module>
    images, labels = data_iter.next()
AttributeError: '_SingleProcessDataLoaderIter' object has no attribute 'next'

Also this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants