Skip to main content

Simple neural network implementation with numpy

Project description

numpynet

Convolutional Neural Network written from scratch using numpy with API similar to tensorflow. Library was compared with tensorflow versions of network (demo directory) and achieved very close results.

Implemented Elements

Layers

  • InputLayer
  • DenseLayer
  • BiasLayer
  • ActivationLayer (relu, leaky reLu, sigmoid, tanh, sin)
  • DropoutLayer
  • FlattenLayer
  • Conv2DLayer (with bias & stride)
  • Pool2DLayer (max, min)
  • Padding2DLayer
  • Crop2DLayer
  • SoftmaxLayer

Losses

  • MSE
  • CCE

Initializers

  • ConstantInitializer
  • RandomNormalInitializer
  • RandomUniformInitializer
  • GlorotUniformInitialization

Metrics

  • CategoricalAccuracy

Callbacks

  • ModelCheckpoint
  • EarlyStopping

Usage Example

Definition

layers = [
    numpynet.layers.InputLayer((28, 28, 1)),
    numpynet.layers.Conv2DLayer(32, kernel_size=3, stride=1),
    numpynet.layers.ActivationLayer('relu'),
    numpynet.layers.FlattenLayer(),
    numpynet.layers.DenseLayer(128),
    numpynet.layers.BiasLayer(),
    numpynet.layers.ActivationLayer('relu'),
    numpynet.layers.DropoutLayer(0.5),
    numpynet.layers.DenseLayer(10),
    numpynet.layers.BiasLayer(),
    numpynet.layers.SoftmaxLayer(),
]

model = numpynet.network.Sequential(layers)

Compilation

model.compile(
    loss='cce',
    metrics=['categorical_accuracy']
)

Fitting

checkpoint_callback = numpynet.callbacks.ModelCheckpoint('checkpoint.dat')

history = model.fit(
    train_x,
    train_y,
    validation_data=(test_x, test_y),
    learning_rate=0.001,
    epochs=10,
    callbacks=[checkpoint_callback],
)

Predicting

predictions = model.predict(test_x)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

numpynet-0.1.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file numpynet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: numpynet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.7

File hashes

Hashes for numpynet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b30ea985b5efb1a113ccecc1640f3d7e105859ae70274ca46c9ff8957beb53a0
MD5 666ba8fa30c7fad5d10f7a3275e64632
BLAKE2b-256 cbacdf4552feb943c8508eeb2af1463e51e2cdc5703bf13463c10d3250bcc27c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page