A neural network model architecture template
Project description
Template NN
Template NN is a lightweight, easy-to-use template designed to serve as a drop-in replacement for PyTorch's core neural network modules, streamlining prototyping and development. It aims to provide a more opinionated and simplified interface while fully leveraging PyTorch's powerful backend.
Huge thanks to the PyTorch team for enabling projects like this.
Installation
[!WARNING] Breaking Changes in Version>=0.1.6
This release includes the removal of optimiser support, directory renames, module restructuring, and function removals. If you're upgrading from an earlier version, please read the Release Notes before updating.
You can install template-nn via pip:
pip install template-nn
Or clone the repository and install it locally:
git clone https://github.com/gabrielchoong/template-nn.git
cd template-nn
pip install -r requirements.txt
pip install .
Documentation
For detailed documentation, including usage instructions and examples, visit the online documentation at Documentation.
Examples
For runnable examples demonstrating how to use template-nn, please refer to the examples/ directory in this repository.
Feature Preview
import torch
import torch.nn as nn
from template_nn import CNN
# --- Using raw PyTorch (Simple CNN) ---
class SimpleCNN(nn.Module):
def __init__(self):
super(SimpleCNN, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.pool(nn.functional.relu(self.conv1(x)))
x = self.pool(nn.functional.relu(self.conv2(x)))
x = torch.flatten(x, 1) # flatten all dimensions except batch
x = nn.functional.relu(self.fc1(x))
x = nn.functional.relu(self.fc2(x))
x = self.fc3(x)
return x
pytorch_cnn_model = SimpleCNN()
# --- Using Template NN (Simple CNN) ---
template_nn_cnn_model = CNN({
"image_size": (32, 32), # Example input image size
"conv_channels": [3, 6, 16],
"conv_kernel_size": 5,
"pool_kernel_size": 2,
"fcn_hidden_sizes": [120, 84],
"activation_functions": [nn.ReLU(), nn.ReLU(), nn.ReLU(), nn.ReLU()], # For conv and fc layers
"output_channel": 10
})
print("PyTorch CNN Model Architecture:")
print(pytorch_cnn_model)
print("\nTemplate NN CNN Model Architecture:")
print(template_nn_cnn_model)
Releases and Contributing
This project is currently in its beta stage. Please file an issue if you found a bug.
To read about the motive and direction of this project, see Roadmap. To read more about the current releases, see Release Notes.
Contributions are welcomed! Please see Contributions for information on contributing.
Contributors
This project is currently being developed by Gabriel.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file template_nn-0.1.6.tar.gz.
File metadata
- Download URL: template_nn-0.1.6.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f14ed579f8cf7c4e468a7c787757d4692ffd6bcea749c5ce64abac0d4ffd7b60
|
|
| MD5 |
40ab96587754314fd0f848af18ec3c4d
|
|
| BLAKE2b-256 |
17a7f00ab84d9dbe75a4ff4567865902305d417f9753ef409ce9a0aa900b1ccf
|
File details
Details for the file template_nn-0.1.6-py3-none-any.whl.
File metadata
- Download URL: template_nn-0.1.6-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76f55569a1734f71ee82776ef67f47ffbb2dd9b01d616b4b9ed4fb2b9e934024
|
|
| MD5 |
d585f7cd1972734f769e8148135d2fba
|
|
| BLAKE2b-256 |
4d98d19c09b72e1374643bf257818d3277fdbfa0bb4a5e04a47c076b55479aba
|