GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mxnet/matlab at master · fixiecoding/mxnet

Expand file tree

/

matlab

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

matlab

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
+mxnet
+mxnet
 
 
tests
tests
 
 
README.md
README.md
 
 
demo.m
demo.m
 
 

README.md

Outline

MATLAB binding for mxnet

How to use

The only requirment is build mxnet to get lib/libmxnet.so. Sample usage

  • Load model and data:

    img = single(imresize(imread('cat.png'), [224 224])) - 120;
    model = mxnet.model;
    model.load('model/Inception_BN', 39);
  • Get prediction:

    pred = model.forward(img);
  • Do feature extraction on GPU 0:

    feas = model.forward(img, 'gpu', 0, {'max_pool_5b_pool', 'global_pool', 'fc'});
  • See demo.m for more examples

Note on Implementation

We use loadlibrary to load mxnet library directly into Matlab and calllib to call MXNet functions. Note that Matlab uses the column-major to store N-dim arraies while and MXNet uses the row-major. So assume we create an array in matlab with

X = zeros([2,3,4,5]);

If we pass the memory of X into MXNet, then the correct shape will be [5,4,3,2] in MXNet. When processing images, MXNet assumes the data layout is

example x channel x width x height

while in matlab we often store images by

width x height x channel x example

So we should permuate the dimensions by X = permute(X, [2, 1, 3, 4]) before passing X into MXNet.

FAQ

  1. You may get the error GLIBCXX_x.x.xx is not found. Such as on Ubuntu 14.04:
> In loadlibrary (line 359)
Error using loadlibrary (line 447)
There was an error loading the library "/home/muli/work/mxnet/lib/libmxnet.so"
/usr/local/MATLAB/R2015a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6:
version `GLIBCXX_3.4.18' not found (required by
/home/muli/work/mxnet/lib/libmxnet.so)

Caused by:
    Error using loaddefinedlibrary
    /usr/local/MATLAB/R2015a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6:
    version `GLIBCXX_3.4.18' not found (required by
    /home/muli/work/mxnet/lib/libmxnet.so)

One way to fix it is to link MATLAB_ROOT/sys/os/glnxa64/libstdc++.so.6 to your system's libstdc++. For example

muli@ghc:/usr/local/MATLAB/R2015a/sys/os/glnxa64$ sudo rm -r libstdc++.so.6
muli@ghc:/usr/local/MATLAB/R2015a/sys/os/glnxa64$ sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19 libstdc++.so.6
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.