Introducing new project: image2sdr



I have uploaded a new project on GitHub called image2sdr. It is a simple NodeJS service which you can post an image file to, and it returns an SDR.

Behind the scenes what it is doing is:

  1. Classify image via Clarifai and return the top 10 concepts and their confidence level
  2. Parse the concepts found and retrieve word SDRs via
  3. Stack the word SDRs, scored by their confidence level
  4. Generate a standard bit-array SDR with the desired sparsity, containing the bits with the top scores (using random tie breaker)

This project is in response to a conversation we had during the most recent Hackers’ Hangout.

Couple of notes:

  1. You will need to copy config_example.yml into a file named config.yml, and enter your own and Clarifai API keys. You can get free API keys from the respective websites.
  2. The service does not currently support proxy settings. If running behind a proxy, you’ll need to add the necessary code
  3. The word SDRs from are not a fixed sparsity (common words are more dense than less common ones), so might need some tweaking of the sparsity and sdr_size parameters (or refactoring if there is a better way)
  4. Multi-word concepts from Clarifai are skipped (such as “hard hat”). To enable them, special consideration will need to be given to negative concepts (such as “no people”).
  5. This is an open source HTM community project, so feel free to make updates and evolve the idea

Bad results anomaly detection

Great job Paul. I just ran it locally and it is working great. There are some fun things to do with this codebase. It was fun to print out all the Clarifai terms for each image I uploaded. It would also be interesting to send each SDR back to Cortical IO to see what one term matches the bag of words best.


I am interested in encoder algorithm.
Could you please:

  1. explain your algorithm Paul?
  2. show us your input image and the output sdr @rhyolight?


@Paul_Lamb Awesome!!!
Here’s an example SDR output that I’ve generated, and I think I’ve done it correctly. :crossed_fingers:





@Jose_Cueto how about image and sdr size? Can you display sdr output as image?
Currently I am working on different concepts, based on extracting image features and converting these features into sdr.


Sure, the basic process is:

  1. Retrieve the concepts found in the image and their level of certainty. For example, ET: .99, creepy: .88, ugly: .75.
  2. Retrieve the word SDRs for each of those concepts (ET, creepy, and ugly in this example).
  3. Loop through the word SDRs and for each “on” bit increase the score for that bit position by the level of certainty for the associated concept.
  4. After adding the scores for all of the SDRs, select the desired sparsity of the bits with the highest scores, using a random tiebreaker.

I called the core algorithm mergeWeightedSdrs. By “weighted SDR” I mean a word SDR and its level of certainty.

No, it is a single-direction encoding. SDRs from images, but not back the other direction.


BTW, if you are referring to the algorithms for images to concepts and words to SDRs, those algorithms are performed outside of the above merging algorithm (in this case, Clarifai is used for concept identification, and is used for word SDRs)

Clarifai uses a convolutional neural network algorithm. uses an algorithm called semantic folding.

This project merges the two to provide a way of generating SDRs from images for use in the HTM algorithms.


@Paul_Lamb thanks for your explain. I do not know about Classifai, but as far as I know CNN does not support online learning and decoding. Am I Right here?


I don’t know the definition of online decoding, but yes CNN is a traditional supervised learning algorithm which requires a large labeled training set. It also has no relation to biological neural networks.


Another way to think of the basic concept, is imagine one person using words to describe something they saw to someone else who wasn’t there. This scene from “Someone Like You” comes to mind:



For anyone interested in doing this, you can use the /expressions/similar_terms API, with a body like:


I did this for the ET image and SDR that @Jose_Cueto posted.

The original concepts found by Clarifai were:

wildlife: .972
portrait: .970
nature: .969
animal: .968
staring: .952
one: .947
eye: .946
face: .945
looking: .927
isolated: .918

Running the SDR through the above similar terms API suggests:

animal  *
looking  *
eye  *
wild  *
face  *
animals  *
eyes  *

(I added a * by the ones which match the original classification). An extraneous “cat” idea seems to have been introduced here, but given the rather non-specific original classification, seems like it did an OK job in this case.


I just want to make sure that @sheiser1 sees this, since he was the one asking about it at the hangout.


A fantastic tool. Big ups @Paul_Lamb!


How can you tell that your algorithm is doing a good job? One way to validate it is reconstructing the original image from the SDR.

Here’s an alternative (and much simpler) approach: just use a sparse autoencoder, trained on a large dataset.


Sure, there are no doubt many other better ways to accomplish this. I put this together after a conversation we had on Hackers’ Hangout, where I mentioned one really quick and dirty way to connect a lot of traditional AI algorithms with HTM is by simply leveraging word SDRs.


Is there anywhere that suggests that the brain reconstructs entire images like this?

Considering that the perception of an image is a constructive process that involves serial scanning of portions of an image there really is no place where “an image” ever exists in the brain at any point.

As far as I know we perceive and recall sequences of tokens that let us construct and reconstruct these properties of an image; as fast as we can consider some aspect of an image that part is reconstructed in recall.

These tokens are initially formed by perception and learning of novel features. From that point these features become available for perceiving and recalling things that contain that feature.

I am excluding the images that are directly and unconsciously processed by sub-cortical structures.


The encoding (feature extraction) done by convolutional layers is inspired by visual cortex [1]



Convolution is inspired by the foveal scanning that extracts these streams of tokens. I understand that the biological mechanisms have been emulated to make a process that is more suited to use by digital hardware but it is an inexact copy of these mechanisms.

There are bunches of good ways to do image processing - I am just pointing out that reconstruction of an image does not seem to be biologically plausible.

The usual focus of HTM researchers is to make something that works in biologically inspired ways to help model and understand the wetware.


Sorry, forgot to answer your question. Typically the best way is to compile a good set of realistic test data and perform whatever prediction or anomaly detection task you are planning, to see how it does.


Perhaps. I don’t think we know enough about how a brain reconstructs an image while trying to visualize something. In this case we use reconstruction as a way to test the quality of an SDR.

In any case, using a convolutional network to encode an image seems to be way more biologically plausible than some of the methods used by