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.dev2.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.dev2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbviz-0.1.4.dev2.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.dev2.tar.gz
Algorithm Hash digest
SHA256 6f8ca4ff7915efa6e45e1f987d6c93e35229f62331786e36cc4a4383c7cac845
MD5 0b605fa0a516df319b4cc4e244442920
BLAKE2b-256 a66a35cc9c7bf8926ba60a0b05c8ed517eceb66e0eb1df87dae0c832dd68e6e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dbviz-0.1.4.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 974538579e13bdb8930892e16f903eac6f240aae479a9b98d60fd739bd2ec7de
MD5 480e803d8dbbcb8f4e72040e834e042a
BLAKE2b-256 6b609cce6594b63864a5f73347467a77161bb25ca01945bc74f98dafca60b3a2

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