A Sparsity Analysis Tool and Library
Project description
hoplite2
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
# 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):
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
hoplite2-0.1.1.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for hoplite2-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad0e5154abf6263c2e3b954a0bffcedb102214f30b611054bfbc2af572170ffd |
|
MD5 | 87992ec3fdf71dceaecd4d4aa834d96d |
|
BLAKE2b-256 | d0ad2010eda0adc4820b03f4398203a75b9819e459b848b7b9abdc0aa1282209 |