Skip to main content

npnn

NumPy Neural Network

PyPI - Version PyPI - Implementation PyPI - Python Version

What's npnn?

npnn is a a torch-like Python module for gradient descent based machine learning implemented with numpy.

Dependency

Basically npnn only depends on numpy(the latest version 1.26.4 is verified).

If you have CUDA devices available, then you can easily get a acceleration by installing suitable version of cupy. In this case npnn will use cupy api rather than numpy api.

For example, my PC have CUDA v12.x (x86_64), so I use command:

pip install cupy-cuda12x
pip install npnn

or in short:

pip install npnn[cuda12x]

check cupy documentation for more information.

API references

See npnn WIKI.

Known issues

See npnn known-issues.

Work with npnn!

Here we will construct a image classification neural network with npnn.

BTW, this is a course assignment of DATA620004, School of Data Science, Fudan University.

Task

Construct and Train a neural network on Fashion-MNIST to do image classification.

  • Implement gradient backpropagation algorithm by hand,you can use numpy but DO NOT use pytorch or tensorflow to do autograd.

  • Submit source code including at least four parts: model definition, training, parameters searching and testing.

Implementation

  • dataset.py: provide Fashion MNIST dataset
  • model.py: model definition
  • train.py: model training
  • search.py: parameters searching
  • test.py: model testing
  • viz.py: visualization
  • utils.py: some misc function, such as save_model

run search.py, you can get a table like:

no train_id accuracy hidden_size batch_size learning_rate regularization regular_strength
0 2024_0423(1713841292) 0.8306 [384] 3 0.002 None 0.0
1 2024_0423(1713845802) 0.8145 [384] 3 0.002 l2 0.1
2 2024_0423(1713849349) 0.8269 [384] 3 0.002 l2 0.01
3 2024_0423(1713853939) 0.8255 [384] 3 0.002 l2 0.005
4 2024_0423(1713857657) 0.8373 [384] 3 0.002 l2 0.001

train log file and saved model weights can be found in ./logs and ./checkpoints folder.

Release files for npnn 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for npnn 0.1.1
File Size Uploaded
npnn-0.1.1.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for npnn 0.1.1
File Interpreter ABI Platform
npnn-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / npnn-0.1.1.tar.gz

Download URL npnn-0.1.1.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cd839ac815b4ec0b054ba0e934336822cf3ca283e4b41546bb5174a640f6dac1
BLAKE2b-256 checksum
How to use checksums
757b0b23417bc02775dd17b93f6562bf1bcc02a32e8d4f7d213f14eee21d4166
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.14

Release files / npnn-0.1.1-py3-none-any.whl

Download URL npnn-0.1.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c79becc4cf0305ec665459f548975a15e4fe660e7933850e5ddc6efa1cee3b93
BLAKE2b-256 checksum
How to use checksums
b72229d69a55b09caf09a789d5c2f17e40f456588bec0be543f8e010222bd2b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.14

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page