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

Issue about 'example/mnist/eth_mnist.py' using --gpu #170

Closed
janilbols opened this issue Dec 26, 2018 · 3 comments
Closed

Issue about 'example/mnist/eth_mnist.py' using --gpu #170

janilbols opened this issue Dec 26, 2018 · 3 comments

Comments

@janilbols
Copy link

Hi all, I'm new about the project and just clone the latest master-branch on my own machine.

I installed the pkg bindsnet with
pip install ., and tried to run the example code 'eth_mnist.py' with gpu mode:
python eth_mnist.py --gpu
but error occurs during runtime:

Loading training labels from serialized object file.
Begin training.
Progress: 0 / 60000 (0.0000 seconds)
Progress: 10 / 60000 (5.3936 seconds)
Progress: 20 / 60000 (5.3005 seconds)
Progress: 30 / 60000 (5.2392 seconds)
Progress: 40 / 60000 (5.2304 seconds)
Progress: 50 / 60000 (5.2242 seconds)
Progress: 60 / 60000 (5.2055 seconds)
Progress: 70 / 60000 (5.1790 seconds)
Progress: 80 / 60000 (5.1758 seconds)
Progress: 90 / 60000 (5.1704 seconds)
Progress: 100 / 60000 (5.2317 seconds)
Progress: 110 / 60000 (5.1757 seconds)
Progress: 120 / 60000 (5.5117 seconds)
Progress: 130 / 60000 (5.5386 seconds)
Progress: 140 / 60000 (5.1558 seconds)
Progress: 150 / 60000 (5.1877 seconds)
Progress: 160 / 60000 (5.1674 seconds)
Progress: 170 / 60000 (5.1508 seconds)
Progress: 180 / 60000 (5.1378 seconds)
Progress: 190 / 60000 (5.1910 seconds)
Progress: 200 / 60000 (5.1521 seconds)
Progress: 210 / 60000 (5.1740 seconds)
Progress: 220 / 60000 (5.1459 seconds)
Progress: 230 / 60000 (5.1683 seconds)
Progress: 240 / 60000 (5.1265 seconds)
Progress: 250 / 60000 (5.1413 seconds)

Traceback (most recent call last):
  File "eth_mnist.py", line 128, in <module>
    % (accuracy['all'][-1], np.mean(accuracy['all']), np.max(accuracy['all'])))
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py", line 2920, in mean
    out=out, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 85, in _mean
    ret = ret.dtype.type(ret / rcount)
AttributeError: 'torch.dtype' object has no attribute 'type'

How do I fix it? My environment? Or should it be the code-version?

Could you give me some hint for running mnist example code using GPU?

@djsaunde
Copy link
Collaborator

Hi @janilbols,

I wasn't able to reproduce this error. Could you send me the output of pip list on your machine?

@janilbols
Copy link
Author

janilbols commented Dec 27, 2018

Hi @djsaunde , this is the output of pip list:

Package                  Version
------------------------ ----------------------
absl-py                  0.6.1
alabaster                0.7.12
astor                    0.7.1
atomicwrites             1.2.1
attrs                    18.2.0
Babel                    2.6.0
backcall                 0.1.0
bindsnet                 0.2.2
bleach                   3.0.2
cachetools               3.0.0
certifi                  2018.11.29
chardet                  3.0.4
cloudpickle              0.6.1
cycler                   0.10.0
Cython                   0.29.2
dask                     1.0.0
decorator                4.3.0
defusedxml               0.5.0
docutils                 0.14
entrypoints              0.2.3
foolbox                  1.8.0
future                   0.17.1
gast                     0.2.0
gitdb2                   2.0.5
GitPython                2.1.11
google-api-core          1.6.0
google-auth              1.6.1
google-cloud             0.34.0
google-cloud-bigquery    1.8.0
google-cloud-core        0.29.0
google-resumable-media   0.3.1
googleapis-common-protos 1.5.5
grpcio                   1.16.0
gym                      0.10.9
h5py                     2.8.0
idna                     2.8
imagesize                1.1.0
ipykernel                5.1.0
ipython                  7.1.1
ipython-genutils         0.2.0
ipywidgets               7.4.2
jedi                     0.13.1
Jinja2                   2.10
jsonschema               2.6.0
jupyter                  1.0.0
jupyter-client           5.2.3
jupyter-console          6.0.0
jupyter-core             4.4.0
Keras                    2.2.4
Keras-Applications       1.0.6
Keras-Preprocessing      1.0.5
kiwisolver               1.0.1
Markdown                 3.0.1
MarkupSafe               1.1.0
matplotlib               3.0.1
mistune                  0.8.4
more-itertools           4.3.0
nbconvert                5.4.0
nbformat                 4.4.0
networkx                 2.2
notebook                 5.7.0
numpy                    1.15.4
opencv-python            3.4.4.19
packaging                18.0
pandas                   0.23.4
pandocfilters            1.4.2
parso                    0.3.1
pathlib2                 2.3.3
pexpect                  4.6.0
pickleshare              0.7.5
Pillow                   5.3.0
pip                      18.1
pluggy                   0.8.0
prometheus-client        0.4.2
prompt-toolkit           2.0.7
protobuf                 3.6.1
ptyprocess               0.6.0
py                       1.7.0
pyasn1                   0.4.4
pyasn1-modules           0.2.2
pycurl                   7.43.0
pyglet                   1.3.2
Pygments                 2.2.0
pygobject                3.20.0
pyparsing                2.3.0
pyproj                   1.9.5.1
pytest                   4.0.2
python-apt               1.1.0b1+ubuntu0.16.4.2
python-dateutil          2.7.5
pytz                     2018.7
PyWavelets               1.0.1
PyYAML                   3.13
pyzmq                    17.1.2
qtconsole                4.4.2
requests                 2.21.0
rsa                      4.0
scikit-image             0.14.1
scikit-learn             0.20.0
scipy                    1.1.0
Send2Trash               1.5.0
setuptools               40.5.0
six                      1.11.0
sklearn                  0.0
smmap2                   2.0.5
snowballstemmer          1.2.1
Sphinx                   1.8.2
sphinx-rtd-theme         0.4.2
sphinxcontrib-websupport 1.1.0
tensorboard              1.12.0
tensorflow-gpu           1.12.0
termcolor                1.1.0
terminado                0.8.1
testpath                 0.4.2
toolz                    0.9.0
torch                    1.0.0
torchvision              0.2.1
tornado                  5.1.1
tqdm                     4.28.1
traitlets                4.3.2
urllib3                  1.24.1
wcwidth                  0.1.7
webencodings             0.5.1
Werkzeug                 0.14.1
wheel                    0.32.2
widgetsnbextension       3.4.2

BTW, the code works well while running on Cpu.

@janilbols
Copy link
Author

Problem solved after changing the script 'eth_mnist.py' line 113 to 116:

accuracy['all'].append(100 * torch.sum(labels[i - update_interval:i].long() \
                                               == all_activity_pred).data.tolist() / update_interval)
accuracy['proportion'].append(100 * torch.sum(labels[i - update_interval:i].long() \
                                               == proportion_pred).data.tolist() / update_interval)

The torch.sum returns a tensor, which can't be operate by numpy. Use .data.tolist() to convert tensor to list, which works.

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

2 participants