A Tensorflow implementation of CapsNet based on Geoffrey Hinton's paper Dynamic Routing Between Capsules
Status:
- The code runs, issue #8 fixed.
- some results of the tag v0.1 version has been pasted out, but not effective as the results in the paper
Daily task
- Adjust margin
- Improve the eval pipeline, integrate it into training pipeline: all you need is
git clone
,cd
andpython main.py
Others
- Here(知乎) is an answer explaining my understanding of Section 4 of the paper (the core part of CapsNet). It may be helpful in understanding the code.
- If you find out any problems, please let me know. I will try my best to 'kill' it ASAP.
In the day of waiting, be patient: Merry days will come, believe. ---- Alexander PuskinIf 😊
- Python
- NumPy
- Tensorflow (I'm using 1.3.0, not yet tested for older version)
- tqdm (for displaying training progress info)
- scipy (for saving image)
Step 1.
Clone this repository with git
.
$ git clone https://github.com/naturomics/CapsNet-Tensorflow.git
$ cd CapsNet-Tensorflow
Step 2.
Download the MNIST dataset, mv
and extract it into data/mnist
directory.(Be careful the backslash appeared around the curly braces when you copy the wget
command to your terminal, remove it)
$ mkdir -p data/mnist
$ wget -c -P data/mnist http://yann.lecun.com/exdb/mnist/{train-images-idx3-ubyte.gz,train-labels-idx1-ubyte.gz,t10k-images-idx3-ubyte.gz,t10k-labels-idx1-ubyte.gz}
$ gunzip data/mnist/*.gz
Step 3. Start the training:
$ pip install tqdm # install it if you haven't installed yet
$ python train.py
the tqdm package is not necessary, just an optional tool for displaying the training progress. If you don't want it, change the loop for in step ...
to for step in range(num_batch)
in train.py
$ python eval.py --is_training False
Results for the 'wrong' version(Details in Issues #8):
- test acc
Epoch | 49 | 51 |
---|---|---|
test acc | 94.69 | 94.71 |
Results after fixing Issues #8:
My simple comments for capsule
- A new version neural unit(vector in vector out, not scalar in scalar out)
- The routing algorithm is similar to attention mechanism
- Anyway, a great potential work, a lot to be built upon
- Finish the MNIST version of capsNet (progress:90%)
- Do some different experiments for capsNet:
- Try Using other datasets
- Adjusting the model structure
- There is another new paper about capsules(submitted to ICLR 2018), a follow-up of the CapsNet paper.