Code Monkey home page Code Monkey logo

nupic.torch's Introduction

Numenta Platform for Intelligent Computing PyTorch libraries

CircleCI

This library integrates selected neuroscience principles from Hierarchical Temporal Memory (HTM) into the pytorch deep learning platform. The current code aims to replicate how sparsity is enforced via Spatial Pooling, as defined in the paper How Could We Be So Dense? The Benefits of Using Highly Sparse Representations.

For detail on the neuroscience behind these theories, read Why Neurons Have Thousands of Synapses, A Theory of Sequence Memory in Neocortex. For a description of Spatial Pooling in isolation, read Spatial Pooling (BAMI).

nupic.torch is named after the original HTM library, the Numenta Platform for Intelligent Computing (NuPIC).

Interested in contributing?

Installation

To install from local source code:

pip install -e .

Or using conda:

conda env create

Test

To run all tests:

pytest

Examples

We've created a few jupyter notebooks demonstrating how to use nupic.torch with standard datasets. You can find these notebooks in the examples/ directory or if you prefer you can open them in Google Colab and start experimenting.

Having problems?

For any installation issues, please search our forums (post questions there). Report bugs here.

nupic.torch's People

Contributors

ayaz-amin avatar lscheinkman avatar lucasosouza avatar mrcslws avatar mvacaporale avatar onejgordon avatar renderist avatar rhyolight avatar subutai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nupic.torch's Issues

test_sparse_weights_1d and test_sparse_weights_2d tests not passing

Hi,

I installed the nupic.torch framework using python setup.py develop as in the readme file. However, when I reach the test phase, all tests are successfully completed except test_sparse_weights_1d and test_sparse_weights_2d. I'm working on windows 10 with python 3.7.6 and pytorch 1.3.

The error Traceback is as follows:

ERROR: test_sparse_weights_1d (tests.sparse_weights_test.TestSparseWeights)

Traceback (most recent call last):
File "c:\users\lenovo\documents\github\nupic.torch\tests\sparse_weights_test.py", line 36, in test_sparse_weights_1d
sparse = SparseWeights(linear, percent_on)
File "C:\Users\Lenovo\Documents\GitHub\nupic.torch\nupic\torch\modules\sparse_weights.py", line 120, in init
super(SparseWeights, self).init(module, weight_sparsity)
File "C:\Users\Lenovo\Documents\GitHub\nupic.torch\nupic\torch\modules\sparse_weights.py", line 78, in init
self.rezero_weights()
File "C:\Users\Lenovo\Documents\GitHub\nupic.torch\nupic\torch\modules\sparse_weights.py", line 143, in rezero_weights
self.module.weight.data[zero_idx] = 0.0
IndexError: tensors used as indices must be long, byte or bool tensors

======================================================================
ERROR: test_sparse_weights_2d (tests.sparse_weights_test.TestSparseWeights)

Traceback (most recent call last):
File "c:\users\lenovo\documents\github\nupic.torch\tests\sparse_weights_test.py", line 53, in test_sparse_weights_2d
sparse = SparseWeights2d(cnn, percent_on)
File "C:\Users\Lenovo\Documents\GitHub\nupic.torch\nupic\torch\modules\sparse_weights.py", line 159, in init
super(SparseWeights2d, self).init(module, weight_sparsity)
File "C:\Users\Lenovo\Documents\GitHub\nupic.torch\nupic\torch\modules\sparse_weights.py", line 78, in init
self.rezero_weights()
File "C:\Users\Lenovo\Documents\GitHub\nupic.torch\nupic\torch\modules\sparse_weights.py", line 187, in rezero_weights
self.module.weight.data.view(self.module.out_channels, -1)[zero_idx] = 0.0
IndexError: tensors used as indices must be long, byte or bool tensors


Ran 21 tests in 0.109s

FAILED (errors=2)
Test failed: <unittest.runner.TextTestResult run=21 errors=2 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=21 errors=2 failures=0>

Torch version issue while installing

I am installing the library on a Jetson Nano with Python 3.6.5, PyTorch 1.9.0 and torch vision 0.10.0. Unfortunately when I run the command pip install -e . I get the following error

Collecting torch<=1.13,>=1.6 (from nupic.torch==0.0.1.dev0)
Could not find a version that satisfies the requirement torch<=1.13,>=1.6 (from nupic.torch==0.0.1.dev0) (from versions: )
No matching distribution found for torch<=1.13,>=1.6 (from nupic.torch==0.0.1.dev0)

What should I do to fix it?

Inconsistency concerning required pytorch version

I cloned the repo and tried to install it with conda env create. After some time I got an error saying that pytorch 1.3.1 was needed. So I changed

pytorch==1.3

to

pytorch==1.3.1

in environment.yml. With that change a new installation completed successfully.

But now I get the following error running python setup.py test:

Searching for torch==1.3.1
Reading https://pypi.org/simple/torch/
No local packages or working download links found for torch==1.3.1
error: Could not find suitable distribution for Requirement.parse('torch==1.3.1')

even though conda env create has downloaded and installed pytorch 1.3.1.

Unable to run example in Colab

When trying to run your sparse-cnn example in Colab there are some version problems that I can not workaround.

With the current installation code:
!pip install git+https://github.com/numenta/nupic.torch.git#egg=nupic.torch
!pip install torch torchvision

I get the following output:

Collecting nupic.torch
Cloning https://github.com/numenta/nupic.torch.git to /tmp/pip-install-b9o0b0it/nupic.torch
Running command git clone -q https://github.com/numenta/nupic.torch.git /tmp/pip-install-b9o0b0it/nupic.torch
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing wheel metadata ... done
Collecting torch==1.4
Downloading https://files.pythonhosted.org/packages/24/19/4804aea17cd136f1705a5e98a00618cb8f6ccc375ad8bfa437408e09d058/torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (753.4MB)
|████████████████████████████████| 753.4MB 20kB/s
Building wheels for collected packages: nupic.torch
Building wheel for nupic.torch (PEP 517) ... done
Created wheel for nupic.torch: filename=nupic.torch-0.0.1.dev0-cp36-none-any.whl size=28916 sha256=6c142169de358b9e077a6a82ebcbf34ec9a4e1e3529b941cd96e601de1452413
Stored in directory: /tmp/pip-ephem-wheel-cache-fgj1_5_e/wheels/16/4f/f8/89dd360bad620bcbb6b468e0243812cdfeb76792b4a79b263d
Successfully built nupic.torch
ERROR: torchvision 0.6.0+cu101 has requirement torch==1.5.0, but you'll have torch 1.4.0 which is incompatible.
Installing collected packages: torch, nupic.torch
Found existing installation: torch 1.5.0+cu101
Uninstalling torch-1.5.0+cu101:
Successfully uninstalled torch-1.5.0+cu101
Successfully installed nupic.torch-0.0.1.dev0 torch-1.4.0
Requirement already satisfied: torchvision in /usr/local/lib/python3.6/dist-packages (0.6.0+cu101)
Collecting torch==1.5.0
Downloading https://files.pythonhosted.org/packages/13/70/54e9fb010fe1547bc4774716f11ececb81ae5b306c05f090f4461ee13205/torch-1.5.0-cp36-cp36m-manylinux1_x86_64.whl (752.0MB)
|████████████████████████████████| 752.0MB 22kB/s
Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision) (7.0.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from torchvision) (1.18.4)
Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch==1.5.0->torchvision) (0.16.0)
ERROR: nupic-torch 0.0.1.dev0 has requirement torch==1.4, but you'll have torch 1.5.0 which is incompatible.
Installing collected packages: torch
Found existing installation: torch 1.4.0
Uninstalling torch-1.4.0:
Successfully uninstalled torch-1.4.0
Successfully installed torch-1.5.0

Then I get a runtime error at
from torchvision import datasets, transforms

"RuntimeError: Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=10.2 and torchvision has CUDA Version=10.1. Please reinstall the torchvision that matches your PyTorch install."

ModuleNotFoundError: No module named 'nupic'

Before reporting a new feature or bug, please see current issues first to avoid duplication.

Please provide a list of commands to replicate the bug, and any text-based console output.

See https://github.com/numenta/nupic.torch/blob/master/CONTRIBUTING.md for more details.

I could not install it at first, so I modified the requirements.txt. The installation seemed to work, as shown below:

C:\Users\AyazA\Downloads\nupic.torch-master>python setup.py install
running install
running bdist_egg
running egg_info
writing nupic.torch.egg-info\PKG-INFO
writing dependency_links to nupic.torch.egg-info\dependency_links.txt
writing requirements to nupic.torch.egg-info\requires.txt
writing top-level names to nupic.torch.egg-info\top_level.txt
reading manifest file 'nupic.torch.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'nupic.torch.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\nupic
creating build\bdist.win-amd64\egg\nupic\torch
copying build\lib\nupic\torch\duty_cycle_metrics.py -> build\bdist.win-amd64\egg\nupic\torch
creating build\bdist.win-amd64\egg\nupic\torch\functions
copying build\lib\nupic\torch\functions\k_winners.py -> build\bdist.win-amd64\egg\nupic\torch\functions
copying build\lib\nupic\torch\functions\__init__.py -> build\bdist.win-amd64\egg\nupic\torch\functions
creating build\bdist.win-amd64\egg\nupic\torch\models
copying build\lib\nupic\torch\models\sparse_cnn.py -> build\bdist.win-amd64\egg\nupic\torch\models
copying build\lib\nupic\torch\models\__init__.py -> build\bdist.win-amd64\egg\nupic\torch\models
creating build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\flatten.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\k_winners.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\sparse_weights.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\__init__.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\__init__.py -> build\bdist.win-amd64\egg\nupic\torch
byte-compiling build\bdist.win-amd64\egg\nupic\torch\duty_cycle_metrics.py to duty_cycle_metrics.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\functions\k_winners.py to k_winners.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\functions\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\models\sparse_cnn.py to sparse_cnn.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\models\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\flatten.py to flatten.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\k_winners.py to k_winners.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\sparse_weights.py to sparse_weights.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\__init__.py to __init__.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\nupic.torch-0.0.1.dev0-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing nupic.torch-0.0.1.dev0-py3.7.egg
Removing c:\python37\lib\site-packages\nupic.torch-0.0.1.dev0-py3.7.egg
Copying nupic.torch-0.0.1.dev0-py3.7.egg to c:\python37\lib\site-packages
nupic.torch 0.0.1.dev0 is already the active version in easy-install.pth

Installed c:\python37\lib\site-packages\nupic.torch-0.0.1.dev0-py3.7.egg
Processing dependencies for nupic.torch==0.0.1.dev0
Searching for numpy==1.17.2
Best match: numpy 1.17.2
Adding numpy 1.17.2 to easy-install.pth file
Installing f2py-script.py script to C:\Python37\Scripts
Installing f2py.exe script to C:\Python37\Scripts

Using c:\python37\lib\site-packages
Finished processing dependencies for nupic.torch==0.0.1.dev0

C:\Users\AyazA\Downloads\nupic.torch-master>pip uninstall nupic.torch
Uninstalling nupic.torch-0.0.1.dev0:
  Would remove:
    c:\python37\lib\site-packages\nupic.torch-0.0.1.dev0-py3.7.egg
Proceed (y/n)? y
  Successfully uninstalled nupic.torch-0.0.1.dev0

C:\Users\AyazA\Downloads\nupic.torch-master>python setup.py install
running install
running bdist_egg
running egg_info
writing nupic.torch.egg-info\PKG-INFO
writing dependency_links to nupic.torch.egg-info\dependency_links.txt
writing requirements to nupic.torch.egg-info\requires.txt
writing top-level names to nupic.torch.egg-info\top_level.txt
reading manifest file 'nupic.torch.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'nupic.torch.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\nupic
creating build\bdist.win-amd64\egg\nupic\torch
copying build\lib\nupic\torch\duty_cycle_metrics.py -> build\bdist.win-amd64\egg\nupic\torch
creating build\bdist.win-amd64\egg\nupic\torch\functions
copying build\lib\nupic\torch\functions\k_winners.py -> build\bdist.win-amd64\egg\nupic\torch\functions
copying build\lib\nupic\torch\functions\__init__.py -> build\bdist.win-amd64\egg\nupic\torch\functions
creating build\bdist.win-amd64\egg\nupic\torch\models
copying build\lib\nupic\torch\models\sparse_cnn.py -> build\bdist.win-amd64\egg\nupic\torch\models
copying build\lib\nupic\torch\models\__init__.py -> build\bdist.win-amd64\egg\nupic\torch\models
creating build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\flatten.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\k_winners.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\sparse_weights.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\modules\__init__.py -> build\bdist.win-amd64\egg\nupic\torch\modules
copying build\lib\nupic\torch\__init__.py -> build\bdist.win-amd64\egg\nupic\torch
byte-compiling build\bdist.win-amd64\egg\nupic\torch\duty_cycle_metrics.py to duty_cycle_metrics.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\functions\k_winners.py to k_winners.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\functions\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\models\sparse_cnn.py to sparse_cnn.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\models\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\flatten.py to flatten.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\k_winners.py to k_winners.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\sparse_weights.py to sparse_weights.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\modules\__init__.py to __init__.cpython-37.pyc
byte-compiling build\bdist.win-amd64\egg\nupic\torch\__init__.py to __init__.cpython-37.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying nupic.torch.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\nupic.torch-0.0.1.dev0-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing nupic.torch-0.0.1.dev0-py3.7.egg
Copying nupic.torch-0.0.1.dev0-py3.7.egg to c:\python37\lib\site-packages
Adding nupic.torch 0.0.1.dev0 to easy-install.pth file

Installed c:\python37\lib\site-packages\nupic.torch-0.0.1.dev0-py3.7.egg
Processing dependencies for nupic.torch==0.0.1.dev0
Searching for numpy==1.17.2
Best match: numpy 1.17.2
Adding numpy 1.17.2 to easy-install.pth file
Installing f2py-script.py script to C:\Python37\Scripts
Installing f2py.exe script to C:\Python37\Scripts

Using c:\python37\lib\site-packages
Finished processing dependencies for nupic.torch==0.0.1.dev0

But when I import nupic.torch, I get this error:

ModuleNotFoundError: No module named 'nupic'

setup is a fail

(nupic) beta@mole:~/disk/tzl/code/nupic.torch-master$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 74, in
tests_require=["pytest>=4.4.0"],
File "/home/beta/anaconda3/envs/nupic/lib/python3.7/site-packages/setuptools/init.py", line 162, in setup
_install_setup_requires(attrs)
File "/home/beta/anaconda3/envs/nupic/lib/python3.7/site-packages/setuptools/init.py", line 157, in _install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "/home/beta/anaconda3/envs/nupic/lib/python3.7/site-packages/setuptools/dist.py", line 702, in fetch_build_eggs
replace_conflicting=True,
File "/home/beta/anaconda3/envs/nupic/lib/python3.7/site-packages/pkg_resources/init.py", line 790, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (pycodestyle 2.6.0 (/home/beta/disk/tzl/code/nupic.torch-master/.eggs/pycodestyle-2.6.0-py3.7.egg), Requirement.parse('pycodestyle<2.6.0,>=2.5.0'), {'flake8'})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.