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


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!