Code Monkey home page Code Monkey logo

pcanet's Introduction

PCANet

PCANet is a deep learning network for image classification.

As the name suggests, weights in the network are calculated by PCA. Because of this characteristics, training of PCANet is extremely fast. Furthermore, class labels are not required in training of PCANet itself.
Details are described in the original paper.

Installation

Just running python3 setup.py install.
If you prefer pip, pip3 install . in the PCANet root directory.

If you want to run on GPU, see the installation guide of Chainer.

Usage

import pcanet as net

# Arguments are basically passed as tuple in the form (height, width) but int is also allowed. 
# If int is given, the parameter will be converted into (size, size) implicitly.
pcanet = net.PCANet(
    image_shape=28,
    filter_shape_l1=2, step_shape_l1=1, n_l1_output=3,  # parameters for the 1st layer
    filter_shape_l2=2, step_shape_l2=1, n_l2_output=3,  # parameters for the 2nd layer
    filter_shape_pooling=2, step_shape_pooling=2        # parameters for the pooling layer
)

# Check whether all pixels can be considered. Raise ValueError if the structure is not valid.
# Calling this function is optional. PCANet works without this line.
pcanet.validate_structure()

pcanet.fit(images_train)  # Train PCANet

# Trained PCANet behaves as a transformer from images into features.
# `images` is a 3d array in the form (n_images, height, width), who are transformed into feature vectors.
X_train = pcanet.transform(images_train)
X_test = pcanet.transform(images_test)

# Fit any models you like
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

See run_mnist.py for more details.

Example

CPU is used if you specify a negative value for the GPU ID

Train

python3 run_mnist.py --gpu <GPU ID> train --out <output directory (default='result')>

Test

python3 run_mnist.py --gpu <GPU ID> test --pretrained-model <path to dir (default='result')>

Changes from the original PCANet

This implementation uses IncrementalPCA instead of the ordinary PCA because the ordinary one consumes huge memory space. So it is not possible to train the model on a large dataset in a limited memory.

Documentation

Documentation can be generated by running make html in the docs directory.

Citation

Chan, Tsung-Han, et al. "PCANet: A simple deep learning baseline for image classification?." IEEE Transactions on Image Processing 24.12 (2015): 5017-5032.

pcanet's People

Contributors

ishitatakeshi avatar

Watchers

 avatar  avatar  avatar

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.