https://github.com/klima7/numpynet
Convolutional Neural Network written from scratch using numpy with API similar to tensorflow.
https://github.com/klima7/numpynet
cnn convolution network nn numpy scratch tensorflow
Last synced: 4 months ago
JSON representation
Convolutional Neural Network written from scratch using numpy with API similar to tensorflow.
- Host: GitHub
- URL: https://github.com/klima7/numpynet
- Owner: klima7
- License: mit
- Created: 2022-10-26T08:41:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-17T23:21:10.000Z (almost 2 years ago)
- Last Synced: 2025-08-25T06:48:51.403Z (5 months ago)
- Topics: cnn, convolution, network, nn, numpy, scratch, tensorflow
- Language: Python
- Homepage:
- Size: 5.16 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
## Installation
```bash
pip install numpynet
```
## 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)
```