Giter VIP home page Giter VIP logo

simplepythoncnn's Introduction

SimplePythonCNN

This is Convolutional Neural Network only in python & numpy. It is simple and slow but will get the job done ๐Ÿ‘

Specification

Weight Initialization : Xavier

Weight Update Policy : ADAM, NAG, Momentum, Vanila

Active Function : ReLU, Sigmoid

Regulization : Droupout(only on fc), L2

Loss Function : Softmax, Logistic

Prerequisites

numpy (+ mkl for intel processors. recommend anaconda)
Used sklearn for LabelEncoder & utils.shuffle on examples.

Example

AND gate and CIFAR-10 examples are included.

from classes.neural_net import NeuralNetwork

lr = 1e-4
l2_reg = 5e-6

# 32 * 32 color image
input_size = (3,32,32)

cnn = NeuralNetwork(input_size,
                    [
                        {'type': 'conv', 'k': 16, 'u_type': 'nag', 'f': 5, 's': 1, 'p': 2},
                        {'type': 'pool'},
                        {'type': 'conv', 'k': 20, 'u_type': 'nag', 'f': 5, 's': 1, 'p': 2},
                        {'type': 'pool'},
                        {'type': 'conv', 'k': 20, 'u_type': 'nag', 'f': 5, 's': 1, 'p': 2},
                        {'type': 'pool'},
                        {'type': 'output', 'k': len(le.classes_), 'u_type': 'adam'}
                    ]
                    , lr, l2_reg=l2_reg)


for i in range(600000):
    loss, acc = cnn.epoch(train_images, train_labels)
    test_loss, test_acc = cnn.predict(train_images, train_labels)

CIFAR-10 example gets ~70% test accuracy in 20 epoch.

API Referecne

classes.NeuralNetwork(input_shape, layer_list, lr, l2_reg=0, dropout_p=1, loss='softmax'):
Parameter Description
input_shape Data's numpy shape.
layer_list List of layers you want to be networked. All of properties goes to **kwargs.
lr Learning rate.
l2_reg L2 regularization lambda.
drouput_p Dropout rate. 0 < dropout_p <= 1
loss Loss function. 'softmax', 'logistic'
# type fc, output
classes.NeuralLayer(input_size, k, u_type='adam', a_type='relu')

# type pool
classes.PoolLayer(input_size, f=2, s=2)

# type conv
classes.ConvLayer(input_size, k, f=3, s=1, p=1, u_type='adam', a_type='relu')
Update Policy u_type
ADAM 'adam'
Momentum 'm'
Vanilla 'v'
NAG 'nag'
Activation Function a_type
ReLU 'relu'
Sigmoid 'sigmoid'

ToDos

  • More update policies.
  • More activation functions.
  • Speed tuning.

License

MIT

simplepythoncnn's People

Contributors

amsukdu avatar ebay-yobae avatar

Watchers

James Cloos 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.