SlipGURU Dipartimento di Informatica e Scienze dell'Informazione Università Degli Studi di Genova

Quickstart guide to PADDLE

Installation

First of all, you need Python. If you do not have it installed yet, shame on you!

The easiest way to install PADDLE is using either the command easy_install, provided by setuptools:

$ easy_install -U paddle

or using pip:

$ pip install -U paddle

Alternatively, you can download the latest source package, uncompress it and install directly from the sources (you may have to run the last command as administrator):

$ tar xvzf PADDLE-latest.tar.gz
$ cd paddle-X.Y.Z
$ python setup.py install

To check the installation, run:

$ python -c "import paddle"

If no message is issued, PADDLE and its dependencies have been installed correctly.

A Quick Example

As an introduction to the use of PADDLE, we briefly describe an example learning a dictionary from a single image.

Here we focus on the essentials. The complete script, oneimage.py, can be found in the examples directory of the source distribution.

First, we load the image and possibly convert it to gray-scale:

    # load the image
    img = sp.misc.imread(sys.argv[1])

    # possibly convert to grayscale
    if img.ndim == 3:
        assert img.shape[2] <= 3, img.shape
        img = sp.mean(img, 2)

For testing, you can use the example image lena_std.png, in the examples directory of the source distribution:

_images/lena_std.png

Then, we extract Nmax image patches of size 12 by 12:

    # extract the patches
    h, w = opts.patchsize, opts.patchsize
    X = paddle.common.img2patches(img, size=(h, w), Nmax=opts.nmax)
    assert X.shape[0] == (h*w), X.shape

    # standardize the patches
    X -= sp.mean(X, 0).reshape((1, -1))

Note that in the last line we get rid of the offset. Here is a subset of sampled patches (as you see, many of them are mostly homogeneous):

_images/patches.png

Finally, we run PADDLE on the patches:

    # call paddle
    K = opts.dictsize
    D0, C0, U0 = paddle.dual.init(X, K)
    D, C, U, full_out = paddle.dual.learn(X, D0, C0, U0, tau=opts.tau, rtol=1.e-8)

Here are the results of a run on 10k patches. First the atoms of the dictionary:

_images/atoms.png

And then the filters (rows) of the dual:

_images/filters.png

That’s it.

Where to go from here

Now, you may want to:

Table Of Contents