Skip to main content

hoplite2

PyPI version

a sparsity analysis tool for neural networks

Installation

pip install hoplite2

Usage

There are 2 main classes that are useful in Hoplite2: Spartan and Hoplite.

The Hoplite Class is the main way to use Hoplite2.

from hoplite2 import Hoplite
from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import preprocess_input
import numpy as np

# keras model to analyze
model = VGG16(
    include_top=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    pooling=None,
    classes=1000,
    classifier_activation="softmax",
)

# preprocess function
def vgg16_preprocess(path):
    img = image.load_img(path, target_size=(224, 224))
    return preprocess_input(np.expand_dims(image.img_to_array(img), axis=0))

hop = Hoplite(model, vgg16_preprocess, layers=[
    "block1_conv2",
    "block2_conv2",
    "block3_conv3",
    "block4_conv3",
    "block5_conv3"
])

hop.analyze_file("test.png") # analyzes test.png

hop.output("output.csv") # saves output to file

Spartan implements several useful functions to analyze sparsity of arrays. These functions include:

 - compute_average_sparsity(output,equals_zero=lambda x: x == 0)
 - consec_1d(arr, hist, equals_zero=lambda x: x == 0)
 - consec_row(output, equals_zero=lambda x: x == 0)
 - consec_col(output, equals_zero=lambda x: x == 0)
 - consec_chan(output, equals_zero=lambda x: x == 0)
 - vec_1d(arr, vec_size, hist, equals_zero=lambda x: x == 0):
 - vec_3d_row(output, vec_size, equals_zero=lambda x: x == 0):
 - vec_3d_col(output, vec_size, equals_zero=lambda x: x == 0):
 - vec_3d_chan(output, vec_size, equals_zero=lambda x: x == 0):

equals_zero is a function that takes in a number and returns True if the number is considered zero. This is useful if you wish to look for values that are also close to zero and allows for additional customizablity.

Metadata

Release files for hoplite2 0.3.0

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

Source distribution (sdist)

Source distribution for hoplite2 0.3.0
File Size Uploaded Provenance Actions
hoplite2-0.3.0.tar.gz 9.0 kB Without provenance Details for hoplite2-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hoplite2 0.3.0
File Interpreter ABI Platform Actions
hoplite2-0.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for hoplite2-0.3.0-py2.py3-none-any.whl

Total release size: 15.2 kB

Release files / hoplite2-0.3.0.tar.gz

Download URL hoplite2-0.3.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1739f78d09a6a1d19df052c02c842d5f9499ec3945758802a1961ae1df50838c
BLAKE2b-256 checksum
How to use checksums
215bfc10177a59c9cb711bf78208a3edbb379fcd17dc0884e7cb7fa465151068
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.24.0

Release files / hoplite2-0.3.0-py2.py3-none-any.whl

Download URL hoplite2-0.3.0-py2.py3-none-any.whl
Size 6.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bb7827d07f4eb68a8e883213849d9aa8c1439ab067fad067724dca756f97235d
BLAKE2b-256 checksum
How to use checksums
311500055f9ff205453a42db42efaa7bdfc62443cc8d850165ebf7b22dc98d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.24.0

Security for hoplite2 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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