Coder Social home page Coder Social logo

dnn-numpy's Introduction

Introduction

Deep Neural Networks implemented in NumPy.
Including Multi-Layer Perceptron, Convolutional Neural Networks, and Recurrent Neural Networks...
Bascily preforming classification task, so Cross Entropy Loss and Batch Stochastic Gradient Descent are implemented.

Require

Python 3
Numpy

MLP-numpy

Principle

MLP

Example

Perfrom MNIST recognition task.
Flatten-FC100-Relu-FC100-Relu-FC10-Softmax
Test_Acc=0.9525 after 500 epoches.

  1. define a Model class
model = Model(name='model', input_dim=[28, 28, 1])  
  1. initial the structure
model.initial(
    [
        Flatten(name='flatten'),
        Dense(name='fc1', units=100),
        Activation(name='A1', method='relu'),
        Dense(name='fc2', units=100),
        Activation(name='A2', method='relu'),
        Dense(name='fc3', units=10),
        Activation(name='A3', method='softmax'),
    ]
)
  1. fit the training set
model.fit(mnist.train_x_set, mnist.train_y_set)
  1. training, print the training log at every interval epoch.
model.train(lr=0.01, momentum=0.9, max_epoch=500, batch_size=128, interval=10)  
  1. print test result
print('Test_Acc=[{}]'.format(model.measure(mnist.test_x_set, mnist.test_y_set)))  

CNN-numpy

Principle

CNN

Example

Perfrom MNIST recognition task.
C5*3*3-Relu-P2*2-Flatten-FC100-Relu-FC10-Softmax
Test_Acc=0.9649 after 500 epoches.

mnist = MNIST(dimension=3)
model = Model(name='model', input_dim=[28, 28, 1])
model.initial(
    [
        Conv2D(name='C1', kernel_size=[3, 3], filters=5, padding='valid'),
        Activation(name='A1', method='relu'),
        MaxPooling2D(name='P1', pooling_size=[2, 2]),
        Flatten(name='flatten'),
        Dense(name='fc1', units=100),
        Activation(name='A3', method='relu'),
        Dense(name='fc2', units=10),
        Activation(name='A4', method='softmax'),
    ]
)
model.fit(mnist.train_x_set, mnist.train_y_set)
model.train(lr=0.01, momentum=0.9, max_epoch=500, batch_size=128, interval=10)
print('Test_Acc=[{}]'.format(model.measure(mnist.test_x_set, mnist.test_y_set)))

Note

Training requires lots of time.
The reason why the training accuracy vibrates is about it computes the accuracy of batch set rather than whole training set.

RNN-numpy

Principle

RNN

Example

Perfrom MNIST recognition task.

mnist = MNIST(dimension=3)
model = Model(name='model', input_dim=[28, 28])
model.initial(
    [
        BasicRNN(name='R1', units=10, return_last_step=False),
        Activation(name='A1', method='relu'),
        BasicRNN(name='R2', units=10, return_last_step=False),
        Activation(name='A2', method='relu'),
        Flatten(name='flatten'),
        Dense(name='fc1', units=10),
        Activation(name='A3', method='softmax'),
    ]
)
model.fit(mnist.train_x_set.squeeze(-1), mnist.train_y_set)
model.train(lr=0.01, momentum=0.9, max_epoch=500, batch_size=128, interval=10)
print('Test_Acc=[{}]'.format(model.measure(mnist.test_x_set.squeeze(-1), mnist.test_y_set)))

dnn-numpy's People

Contributors

kenncoder7 avatar

Watchers

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