Coder Social home page Coder Social logo

capsnet.mxnet's Introduction

CapsNet-MXNet

This example is MXNet implementation of CapsNet:
Sara Sabour, Nicholas Frosst, Geoffrey E Hinton. Dynamic Routing Between Capsules. NIPS 2017

  • The current best test error is 0.29% and average test error is 0.303%
  • The average test error on paper is 0.25%

Log files for the error rate are uploaded in repository.


Usage

Install scipy with pip

pip install scipy

Install tensorboard with pip

pip install tensorboard

On Single gpu

python capsulenet.py --devices gpu0

On Multi gpus

python capsulenet.py --devices gpu0,gpu1

Full arguments

python capsulenet.py --batch_size 100 --devices gpu0,gpu1 --num_epoch 100 --lr 0.001 --num_routing 3 --model_prefix capsnet

Prerequisities

MXNet version above (0.11.0)
scipy version above (0.19.0)


Results

Train time takes about 36 seconds for each epoch (batch_size=100, 2 gtx 1080 gpus)

CapsNet classification test error on MNIST

python capsulenet.py --devices gpu0,gpu1 --lr 0.0005 --decay 0.99 --model_prefix lr_0_0005_decay_0_99 --batch_size 100 --num_routing 3 --num_epoch 200

Trial Epoch train err(%) test err(%) train loss test loss
1 120 0.06 0.31 0.0056 0.0064
2 167 0.03 0.29 0.0048 0.0058
3 182 0.04 0.31 0.0046 0.0058
average - 0.043 0.303 0.005 0.006

We achieved the best test error rate=0.29% and average test error=0.303%. It is the best accuracy and fastest training time result among other implementations(Keras, Tensorflow at 2017-11-23). The result on paper is 0.25% (average test error rate).

Implementation test err(%) ※train time/epoch GPU Used
MXNet 0.29 36 sec 2 GTX 1080
tensorflow 0.49 ※ 10 min Unknown(4GB Memory)
Keras 0.30 55 sec 2 GTX 1080 Ti

capsnet.mxnet's People

Contributors

soonhwan-kwon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

capsnet.mxnet's Issues

hi,I have something wrong to run your code ,let me show the details.

my env is python3 with mxnet 0.12.1

Traceback (most recent call last):
  File "capsulenet.py", line 303, in <module>
    path + 'train-labels-idx1-ubyte.gz', path + 'train-images-idx3-ubyte.gz')
  File "capsulenet.py", line 106, in read_data
    with gzip.open(download_data(label_url)) as flbl:
  File "capsulenet.py", line 101, in download_data
    urllib.urlretrieve(url, fname)
AttributeError: module 'urllib' has no attribute 'urlretrieve'

I know that it is a little problem ,so I change urllib.urlretrieve with urllib.request.urlretrieve,then I have another problem

(mxnet) x@x:~/me/capsule/capsnet.mxnet$ python capsulenet.py --devices gpu0
batch_size: 100
decay: 0.9
devices: gpu0
lr: 0.001
model_prefix: capsnet
num_epoch: 100
num_routing: 3
recon_loss_weight: 0.392
tblog_dir: tblog
Traceback (most recent call last):
  File "capsulenet.py", line 338, in <module>
    final_net = capsnet(batch_size=args.batch_size/num_gpu, n_class=10, num_routing=args.num_routing, recon_loss_weight=args.recon_loss_weight)
  File "capsulenet.py", line 56, in capsnet
    primarycaps.infer_shape(data=(batch_size, 1, 28, 28))
  File "/home/x/.local/virtualenvs/mxnet/lib/python3.5/site-packages/mxnet/symbol/symbol.py", line 965, in infer_shape
    res = self._infer_shape_impl(False, *args, **kwargs)
  File "/home/x/.local/virtualenvs/mxnet/lib/python3.5/site-packages/mxnet/symbol/symbol.py", line 1085, in _infer_shape_impl
    c_array_buf(mx_uint, array('I', sdata)),
TypeError: integer argument expected, got float

could you have time to help me understand why it happes?

support gpu version

There is a issue when using gpu,
FCCopmute register error for linalg_gemm2.

Suggestion: add an example that uses ImageRecordIterator with RGB images

Hi Soonhwan,

Thanks for creating this repo. This first implementation of CapsNet in MxNet is quite useful. It is great to be able to (almost) reproduce the performances of the paper on MNIST. To be more generally useful, a great addition to your repo would be to add an example using the ImageRecordIterator on RGB images which is what is generally used / needed.

Pierre

c_array_buf(mx_uint, array('I', sdata)), TypeError: array item must be integer

$ python3.6 capsulenet.py --batch_size 90 --devices cpu0,cpu1,cpu2,cpu3,cpu4,cpu5,cpu6,cpu7,cpu8 --num_epoch 100 --lr .001 --num_routing 3 --decay .99 --model_prefix lr_0_0005_decay_0_99
capsulenet.py:108: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  label = np.fromstring(flbl.read(), dtype=np.int8)
capsulenet.py:111: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  image = np.fromstring(fimg.read(), dtype=np.uint8).reshape(len(label), rows, cols)
batch_size: 90
decay: 0.99
devices: cpu0,cpu1,cpu2,cpu3,cpu4,cpu5,cpu6,cpu7,cpu8
lr: 0.001
model_prefix: lr_0_0005_decay_0_99
num_epoch: 100
num_routing: 3
recon_loss_weight: 0.392
tblog_dir: tblog
==================== NUMBER OF GPU:  9

Traceback (most recent call last):
  File "capsulenet.py", line 339, in <module>
    final_net = capsnet(batch_size=args.batch_size/num_gpu, n_class=10, num_routing=args.num_routing, recon_loss_weight=args.recon_loss_weight)
  File "capsulenet.py", line 56, in capsnet
    primarycaps.infer_shape(data=(batch_size, 1, 28, 28))
  File "/usr/local/lib/python3.6/site-packages/mxnet-1.0.0-py3.6.egg/mxnet/symbol/symbol.py", line 965, in infer_shape
    res = self._infer_shape_impl(False, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/mxnet-1.0.0-py3.6.egg/mxnet/symbol/symbol.py", line 1085, in _infer_shape_impl
    c_array_buf(mx_uint, array('I', sdata)),
TypeError: array item must be integer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.