Skip to main content

Decision Boundary Visualization for PyTorch Models

Project description

dbViz — Decision Boundary Visualizer

Minimal install and quickstart to plot decision boundaries for PyTorch models.

Installation

uv sync

Quickstart

A tiny example that selects three samples, builds a plane loader, and plots decision boundaries:

import torch
import torchvision
import torchvision.transforms as transforms
from dbviz.utils import get_random_samples, make_plane_loader
from dbviz.plot import plot_decision_boundaries
import matplotlib.pyplot as plt

# 1. Load a dataset
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))])
testset = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=transform)
classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck')

# 2. Load a model (using an untrained model for this example)
model = torchvision.models.resnet18(weights=None, num_classes=10)
model.eval()

# 3. Pick three samples from your dataset
cifar10_samples, cifar10_labels = get_random_samples(testset)

# 4. Build a plane loader
plane_loader = make_plane_loader(cifar10_samples, batch_size=256, plane_size=500)

# 5. Plot and save
fig = plot_decision_boundaries(model, cifar10_labels, plane_loader, num_classes=len(classes), plane_size=500)
fig.savefig('decision_boundaries_cifar10.png')
plt.show()

Acknowledgement

This package is inspired by:

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

dbviz-0.1.4.dev1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbviz-0.1.4.dev1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file dbviz-0.1.4.dev1.tar.gz.

File metadata

  • Download URL: dbviz-0.1.4.dev1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for dbviz-0.1.4.dev1.tar.gz
Algorithm Hash digest
SHA256 82f6c72eae6e3875363f9df84a5c4a54a144c3c90ef4b4380feae7f4c1716796
MD5 2a0ae18ee32c5e569bffc8add17cc111
BLAKE2b-256 fef94b7b6926a538db29422b95c2d722b5fc36d998fa1c276cf3f003d84a0ff0

See more details on using hashes here.

File details

Details for the file dbviz-0.1.4.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for dbviz-0.1.4.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 d15768e6d6520b5d0b9278427954b118697f4c6485a15968908714d303ddad13
MD5 afae1dee370b407dc787f4bc3b6914fd
BLAKE2b-256 4026d50bb07a0d997507baabfa98a4f53267c97bba1a297e6c496779c0fa4fbd

See more details on using hashes here.

Supported by

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