The code is largely based on the original TensorFlow-implementation by Google engineer Sachin Joglekar's in his blogpost.
Here is the mandatory screenshot.
Although I could find--at the time of this writing--another implementation of a 2D-SOM in PyTorch in this repository which was also heavily based on the original TensorFlow implementation, the PyTorch code ran too slowly.
So, here's an implementation that runs fast (relatively). Enjoy! 👍
The som.py
file contains the class definition of a 2D-SOM. Feel free to
tweak it to your needs.
The colorsome.py
file showcases a nice example of using the SOM2D
class from
som.py
to cluster the RGB color space.