High-Performance Computer Vision & Deep Learning Framework in C++ & CUDA with PyTorch Parity
Project description
🌌 newton-vision
High-Performance Computer Vision & Deep Learning Framework in C++17 & CUDA with PyTorch Parity.
newton-vision is a lightweight, zero-dependency deep learning framework built from scratch with custom native C++17 OpenMP multi-threading, CUDA GPU global kernels, reverse-mode Autograd DAG Engine, Vision Model Zoo (ResNet-18, MobileNetV2), and seamless PyTorch state_dict weight loading.
🚀 Quick Installation
Install the official binary wheel directly from PyPI:
pip install newton-vision
Or build directly from source:
git clone https://github.com/onur/newton-vision.git
cd newton-vision
pip install .
⚡ Quick Start: 60-Second Training Example
import numpy as np
import newton_vision as nv
# 1. Device Control & Tensor Allocation
device = "cuda" if nv.principia.is_cuda_available() else "cpu"
# 2. Build a CNN Model Architecture
class ConvNet:
def __init__(self):
self.conv = nv.Conv2d(in_channels=1, out_channels=8, kernel_size=3, padding=1)
self.relu = nv.ReLU()
self.pool = nv.MaxPool2d(kernel_size=2)
self.fc = nv.Linear(in_features=8 * 14 * 14, out_features=10)
def forward(self, x):
h = self.pool(self.relu(self.conv(x)))
flat = h.data.reshape(h.data.shape[0], -1)
return self.fc(flat)
model = ConvNet()
criterion = nv.gravity.CrossEntropyLoss()
optimizer = nv.gravity.Adam(model.conv.parameters() + model.fc.parameters(), lr=0.01)
# 3. Dummy Synthetic Digit Training Iteration
x_data = nv.Tensor(np.random.randn(4, 1, 28, 28).astype(np.float32), requires_grad=True)
y_target = np.array([0, 3, 7, 9], dtype=np.int64)
optimizer.zero_grad()
logits = model.forward(x_data)
loss = criterion(logits, y_target)
# 4. Reverse-Topological Autograd Graph Execution
loss.backward()
optimizer.step()
print(f"Loss: {loss.data.item():.4f} | Conv Weight Grad Max: {np.max(np.abs(model.conv.w.grad)):.4f}")
🏛️ Architecture & Module Organization (Newton System)
The framework is organized into modular Newton-themed components:
| Module | Description | Key Components |
|---|---|---|
nv.optics |
Vision Layers API | Conv2d, Linear, BatchNorm2d, MaxPool2d, AvgPool2d, ReLU, LeakyReLU, Sigmoid, Tanh |
nv.fluxion |
Autograd Graph Engine | Tensor, backward(), .cuda(), .cpu(), .to(device) |
nv.gravity |
Loss & Optimizers | MSELoss, CrossEntropyLoss, SGD, Adam |
nv.principia |
System & Device Management | is_cuda_available(), get_device(), set_device() |
nv.models |
Vision Model Zoo | ResNet18, MobileNetV2, resnet18(), mobilenet_v2() |
nv.weights |
Weight Importer | load_state_dict(model, state_dict) (PyTorch .pth Parity) |
nv.jit |
Real-Time Server & Exporter | InferenceEngine, save_model, load_model, export_onnx |
🦁 Vision Model Zoo & PyTorch Weight Importer
1. Load Pretrained PyTorch Weights into newton-vision
import numpy as np
import newton_vision as nv
# Instantiate newton-vision ResNet-18 model
model = nv.models.resnet18(num_classes=1000)
# Load state_dict weights exported from PyTorch
pytorch_state_dict = {
"conv1.weight": np.random.randn(64, 3, 7, 7).astype(np.float32),
"fc.weight": np.random.randn(1000, 512).astype(np.float32)
}
nv.load_state_dict(model, pytorch_state_dict)
# Run Inference
dummy_image = np.random.randn(1, 3, 224, 224).astype(np.float32)
logits = model(dummy_image)
print(f"ResNet-18 Logits Output Shape: {logits.shape}") # Output: (1, 1000)
2. MobileNetV2 Depthwise Separable Convolutions
import newton_vision as nv
mobilenet = nv.models.mobilenet_v2(num_classes=1000)
output = mobilenet(np.random.randn(1, 3, 224, 224).astype(np.float32))
print(f"MobileNetV2 Output: {output.shape}")
⏱️ Real-Time Inference Server & ONNX Exporter
import newton_vision as nv
import numpy as np
model = nv.models.resnet18(num_classes=10)
engine = nv.InferenceEngine(model)
# Run high-speed frame-by-frame prediction
frame = np.random.randn(1, 3, 224, 224).astype(np.float32)
output, latency_ms, fps = engine.predict(frame)
print(f"Latency: {latency_ms:.2f} ms | Throughput: {fps:.1f} FPS")
# Save model checkpoint in compressed .nv binary format
nv.save_model(model, "resnet_checkpoint.nv")
# Export computational graph to standard ONNX format
nv.export_onnx(model, frame, "resnet_model.onnx")
📊 Benchmark: newton-vision vs PyTorch 2.6.0 CPU
Execution time for single Conv2D layer forward pass (kernel 3x3, padding 1):
| Test Configuration | newton-vision C++ OpenMP |
PyTorch 2.6 CPU | Throughput (newton-vision) |
|---|---|---|---|
| Batch=1 (128x128, 3➔16 ch) | 1.55 ms | 0.16 ms | 644.9 FPS |
| Batch=8 (64x64, 16➔32 ch) | 11.27 ms | 1.61 ms | 710.0 FPS |
| Batch=16 (32x32, 32➔64 ch) | 19.59 ms | 2.79 ms | 816.8 FPS |
📄 License
newton-vision is released under the open-source MIT License.
Project details
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 newton_vision-1.0.1.tar.gz.
File metadata
- Download URL: newton_vision-1.0.1.tar.gz
- Upload date:
- Size: 365.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ef9dc1f83c669de390ff0f3d0fd0d87bac44b18f95346c49d4b5cd5973ed66a
|
|
| MD5 |
ea48686d430134cb543c3f93d280736d
|
|
| BLAKE2b-256 |
c7228249776c37dc24259999fd61355f3bd2bd822b3a334e5f953440846eb40b
|
File details
Details for the file newton_vision-1.0.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: newton_vision-1.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 192.4 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8564ea8e1f06e7c890084dfc8e1c1088be5f503c9d800231b66acf9cbd91c129
|
|
| MD5 |
ce4fec8742f476f8de42d7839be878a3
|
|
| BLAKE2b-256 |
a0f45839d588e40548a1d3e7f91f01def8edb8083ea72d15dde4ffbfa9499c2d
|