Tensorflow 2.X implementation of Sparse Layer.
Project description
Sparse Layer - Tensorflow
An implementation of Sparse Layers in tensorflow 2.x. Implementation of layers of Dense and Conv2D has been done. Other layers will be added.
Demo
Install
$ pip install sparselayer-tensorflow
Usage
Sparse Convolution Network with Sparse Fully Connected on Head
import tensorflow as tf
from tensorflow.keras.layers import Input, ReLU, BatchNormalization, Flatten, MaxPool2D
from sparselayer_tensorflow import SparseLayerConv2D, SparseLayerDense
# Create Convolution Network
X = tf.keras.layers.Input(shape=(28, 28, 1))
x = SparseLayerConv2D(n_filters=32, density=0.5, filter_size=(3,3), stride=(1,1), padding='SAME')(X)
x = BatchNormalization()(x)
x = ReLU()(x)
x = MaxPool2D((2,2))(x)
x = SparseLayerConv2D(n_filters=64, density=0.5, filter_size=(3,3), stride=(1,1), padding='SAME')(x)
x = BatchNormalization()(x)
x = ReLU()(x)
x = MaxPool2D((2,2))(x)
x = Flatten()(x)
# Added Sparse Dense
y = SparseLayerDense(units=10, density=0.2, activation=tf.nn.softmax)(x)
model = tf.keras.models.Model(X, y)
# Hyperparameters
batch_size=256
epochs=30
# Compile the model
model.compile(
optimizer=tf.keras.optimizers.Adam(0.0001), # Utilize optimizer
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
metrics=['accuracy'])
# Train the network
history = model.fit(
x_train,
y_train,
batch_size=batch_size,
validation_split=0.1,
epochs=epochs)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for sparselayer-tensorflow-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 083d6e1d3f6de1f8c0d123824547e1b54d267bafff469b6bf50159f11bef9f0a |
|
MD5 | 10fa09196909ba3c86333d84ec15ce88 |
|
BLAKE2b-256 | 3a120459092467cffe8b44626fc54157c41cbb8a7c1f94f5d15d6bebde44a775 |