Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

verifiNN

Robustness is a desirable property in a neural network. Informally, robustness can be described as ‘resilience to perturbations in the input’. Said differently, a neural network is robust if small changes to the input produce small or no changes to the output. In particular, if the network is a classifier, robustness means that inputs close to each other should be assigned the same class by the network.

This project implements convex optimization based methods for robustness verification of neural networks. Given a trained neural network and an input, we use an optimization based approach to determine if the network is robust at the input point. Currently only a Linear Programming based approach is supported for ReLU as well as Idenditity activated feed-forward neural networks. Future work will include a Semidefinite Programming based approach for fully connected as well as convolutional neural networks.

For a detailed treatment of the mathematical background, check out this blog post. Here is a small example on how to use verifiNN.

Example

pip install verifiNN
import numpy as np

from verifiNN.models.network import Network
from verifiNN.verifier import LPVerifier

Here we generate a toy network for our example. In reality, this network would be given to us.

# Defining a network
W1 = np.array([[1, 0],
              [0, 1]])
b1 = np.array([1, 1])
W2 = np.array([[0, 1],
              [1, 0]])
b2 = np.array([2, 2])

weights = [W1, W2]
biases = [b1, b2]
network = Network(weights, biases, activation='ReLU', labeler='argmax')

Next, we note the class label that the network assigns to a reference input x_0.

x_0 = np.array([1, 2])
l_0 = network.classify(x_0)  # class 0
assert l_0 == 0

Then, we compute the pointwise robustness (i.e. the distance to the nearest adversarial example within an $\epsilon-$Ball around the reference point.

epsilon = 1.5

vf = LPVerifier()
result = vf.compute_pointwise_robustness(network, x_0, epsilon)
assert result['verification_status'] == 'verified'
assert result['robustness_status'] == 'not_robust'

verifiNN was able to verify that the above nework is NOT robust at x_0. This is because an adversarial example was found within the $\epsilon-$Ball around x_0 (as shown below).

rho = np.round(result['pointwise_robustness'], decimals=5)
assert rho == 0.5  # distanc to nearest adverarial example

x_hat = result['adversarial_example']
assert np.round(x_hat[0], decimals=5) == 1.5
assert np.round(x_hat[1], decimals=5) == 1.5

assert network.classify(x_hat) == 1  # class 1

The adversarial example (1.5, 1.5) lies inside (actually, on the boundary of) the $\epsilon-$Ball around x_0. Yet, as expected, the network assigns the class label 1 to x_hat.

Caution: verifiNN currently suffers from a limitation - if an adversarial example is found, then clearly the network is not robust. However, the converse is not true. In other words, if no adversarial example was found (i.e. the underlyin optimization problem was infeasible) we cannot conclude that the network is robust. This limitation comes from the affine appoximation of the ReLU function in the current lineaer programming based approach. Alternative appraoches (to be implemented in the future) do not suffer from this limitation.

References:

Release files for verifiNN 0.0.0.dev10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for verifiNN 0.0.0.dev10
File Size Uploaded
verifiNN-0.0.0.dev10.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for verifiNN 0.0.0.dev10
File Interpreter ABI Platform
verifiNN-0.0.0.dev10-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / verifiNN-0.0.0.dev10.tar.gz

Download URL verifiNN-0.0.0.dev10.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cb19c9f724df668006703b12d1a09f0b7f3bab758e0bfdd6a43aac444fca7455
BLAKE2b-256 checksum
How to use checksums
c62d48a73d978f1abb9e8835493d0cbc8614e603af1ffeabd364a4820cb79716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release files / verifiNN-0.0.0.dev10-py3-none-any.whl

Download URL verifiNN-0.0.0.dev10-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31885be38a20efab46b8c5883e413d9d30326405f77fd7213cf382624fe5cc4d
BLAKE2b-256 checksum
How to use checksums
d294722c0ef62d84f6482d913dec99085ae430689364df3398d859ff43101419
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page