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

Retina encoder: biological encoder for vision WIP #691

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e873102
Retina encoder: initial commit
ctrl-z-9000-times Sep 26, 2019
914d46b
Eye/Retina Encoder - progress.
ctrl-z-9000-times Sep 27, 2019
69d6953
Merge branch 'master_community' into retina_encoder
breznak Sep 28, 2019
3edddad
Retina: fix imports
breznak Oct 1, 2019
ce1e68b
Eye: improve documentation
breznak Oct 2, 2019
2eace9e
Eye: remove resulution_factor as argument
breznak Oct 2, 2019
692aec9
Eye: rm arg fovea_scale
breznak Oct 2, 2019
b803886
Eye: add argument mode: both/parvo/magno
breznak Oct 2, 2019
de65135
Eye: fix parvo:magno cells ratio
breznak Oct 2, 2019
e2014ea
Eye: color vs B/W mode
breznak Oct 2, 2019
f259ec6
Eye: argument plot=False
breznak Oct 2, 2019
57fd3b0
Eye: remove image_file member
breznak Oct 2, 2019
f014438
Eye: remove EyeSensorSampler class as unneeded
breznak Oct 2, 2019
45da86c
Eye: fix parvo/magno split mode
breznak Oct 2, 2019
97e6f57
Revert "Eye: argument plot=False"
breznak Oct 2, 2019
2cc80e1
Eye: comments
breznak Oct 2, 2019
7ae83bf
Eye: compute accepts pos,rot,scale args
breznak Oct 2, 2019
0a908cf
Eye: comments
breznak Oct 2, 2019
99592e9
Eye: improve doc
breznak Oct 3, 2019
61808fa
Eye: fix sparsity of 3D parvo cells
breznak Oct 3, 2019
60c607c
doc
breznak Oct 3, 2019
69f8d93
Eye: self.magno_sdr, parvo_sdr
breznak Oct 3, 2019
ef8d0d6
Eye: plot parvo/magno SDR
breznak Oct 3, 2019
10854ac
Merge branch 'master_community' into retina_encoder
breznak Oct 3, 2019
cf7488f
Merge branch 'master_community' into retina_encoder
breznak Oct 3, 2019
e44d1b1
Merge branch 'master' into retina_encoder
breznak Oct 3, 2019
5bab05e
Merge branch 'master_community' into retina_encoder
breznak Oct 21, 2019
6cb832c
Retina encoder: split to sparsityParvo,Magno
breznak Oct 21, 2019
06a100d
Doc for Channel encoder
breznak Oct 21, 2019
af0a85a
Eye: cleanup
breznak Oct 21, 2019
e6137c3
Eye: cleanup
breznak Oct 21, 2019
ad3e119
Eye: replace PIL with cv2
breznak Oct 22, 2019
ff5b47d
Merge branch 'retina_encoder' of https://github.com/htm-community/nup…
breznak Oct 22, 2019
d5e3302
Eye: fixes
breznak Oct 22, 2019
32a4e49
Eye: add test
breznak Oct 22, 2019
45eb075
CI: split tests to c++/bindings/python
breznak Oct 22, 2019
fc022d6
Merge branch 'master' into retina_encoder
breznak Oct 22, 2019
7f90a1a
Eye: review
breznak Oct 22, 2019
8025d82
Eye: improve test
breznak Oct 22, 2019
4e8b781
Eye: provide dimensions, size
breznak Oct 23, 2019
854b450
MNIST: use Retina image encoder WIP
breznak Oct 23, 2019
ede598d
Eye: fix dimensions
breznak Oct 23, 2019
f93c904
Eye: fix test
breznak Oct 23, 2019
aa3aea8
Eye: fixes for running only one of parvo/magno
breznak Oct 23, 2019
2c94dbb
fixes in mnist + eye
breznak Oct 23, 2019
a063676
Eye: improve main example
breznak Oct 23, 2019
80747f5
Eye: doc parameters
breznak Oct 23, 2019
2e50635
Eye: crop ROI to circle
breznak Oct 23, 2019
362ba32
Eye: draw boundary around fovea
breznak Oct 23, 2019
fddbcba
Eye: apply rotation before retina processing
breznak Oct 23, 2019
565e69e
Eye: use Retina's log sampling
breznak Oct 23, 2019
116a91a
Eye: run example
breznak Oct 23, 2019
be40a5d
Eye: fix scaling
breznak Oct 23, 2019
d7c898e
Eye: bigger steps in random walk
breznak Oct 23, 2019
b4100a2
eye: plot also the whole scene
breznak Oct 23, 2019
3a6461c
Eye: compute has image is argument
breznak Oct 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ jobs:
- name: build htmcore with setup.py
run: python setup.py install --user --force

- name: C++ & Python Tests
run: python setup.py test
- name: C++ Tests
shell: bash
run: ./build/Release/bin/unit_tests

- name: Python Bindings Tests
shell: bash
run: pytest bindings/py/tests

- name: Python (pure) Tests
shell: bash
run: pytest py/tests

- name: Memory leaks check (valgrind)
if: matrix.os == 'ubuntu-18.04'
Expand Down
606 changes: 606 additions & 0 deletions py/htm/encoders/eye.py

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions py/htm/examples/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from htm.bindings.algorithms import SpatialPooler, Classifier
from htm.bindings.sdr import SDR, Metrics
from htm.encoders.eye import Eye


def load_ds(name, num_test, shape=None):
Expand Down Expand Up @@ -90,9 +91,13 @@ def main(parameters=default_parameters, argv=None, verbose=True):
random.shuffle(training_data)

# Setup the AI.
enc = SDR(train_images[0].shape)
encoder = Eye(output_diameter=train_images[0].shape[0],
sparsityParvo = 0.2,
sparsityMagno = 0.0,
color = True)

sp = SpatialPooler(
inputDimensions = enc.dimensions,
inputDimensions = encoder.dimensions,
columnDimensions = parameters['columnDimensions'],
potentialRadius = parameters['potentialRadius'],
potentialPct = parameters['potentialPct'],
Expand All @@ -115,7 +120,10 @@ def main(parameters=default_parameters, argv=None, verbose=True):
# Training Loop
for i in range(len(train_images)):
img, lbl = random.choice(training_data)
encode(img, enc)
encoder.new_image(img)
(enc, _) = encoder.compute()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP on MNIST, not yet tuned. I should revert these changes for now.

if i == 1:
encoder.plot()
sp.compute( enc, True, columns )
sdrc.learn( columns, lbl ) #TODO SDRClassifier could accept string as a label, currently must be int

Expand All @@ -125,7 +133,7 @@ def main(parameters=default_parameters, argv=None, verbose=True):
# Testing Loop
score = 0
for img, lbl in test_data:
encode(img, enc)
enc = encode(img)
sp.compute( enc, False, columns )
if lbl == np.argmax( sdrc.infer( columns ) ):
score += 1
Expand Down
29 changes: 29 additions & 0 deletions py/tests/encoders/eye_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

""" Unit tests for retina encoder. """

import unittest
import os
import numpy as np

from htm.encoders.eye import Eye

class EyeEncoderTest(unittest.TestCase):
""" Unit tests for Eye encoder class. """
ctrl-z-9000-times marked this conversation as resolved.
Show resolved Hide resolved

def testBasicUsage(self):
eye = Eye()
eye.reset()
FILE=os.path.join('py','tests','encoders','ronja_the_cat.jpg')
eye.new_image(FILE)
eye.scale = 0.5
#eye.center_view()
eye.position = (400,400)
for _ in range(10):
pos,rot,sc = eye.small_random_movement()
(sdrParvo, sdrMagno) = eye.compute(pos,rot,sc)
#eye.plot(delay=500)
print("Sparsity parvo: {}".format(len(eye.parvo_sdr.sparse)/np.product(eye.parvo_sdr.dimensions)))
print("Sparsity magno: {}".format(len(eye.magno_sdr.sparse)/np.product(eye.magno_sdr.dimensions)))
assert(eye.dimensions == (1,1))


Binary file added py/tests/encoders/ronja_the_cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ prettytable>=0.7.2 # for monitor-mixin in htm.advanced (+its tests)
## optional dependencies, such as for visualizations, running examples
# should be placed in setup.py section extras_require. Install those by
# pip install htm.core[examples]
opencv-contrib-python #for cv2.bioinspired for RetinaEncoder
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ def configure(platform, build_type):
extras_require={'scikit-image>0.15.0':'examples',
'sklearn':'examples',
'matplotlib':'examples',
'PIL':'examples',
'scipy':'examples'
},
'scipy':'examples',
'opencv-contrib-python': 'examples', #for cv2.bioinspired for RetinaEncoder
},
zip_safe=False,
cmdclass={
"clean": CleanCommand,
Expand Down