ShapeGuard is a tool to help with handling shapes in Tensorflow.
Project description
Shape Guard
ShapeGuard is a tool to help with handling shapes in Tensorflow.
Basic Usage
import tensorflow as tf
from shapeguard import ShapeGuard
sg = ShapeGuard()
img = tf.ones([64, 32, 32, 3])
flat_img = tf.ones([64, 1024])
labels = tf.ones([64])
# check shape consistency
sg.guard(img, "B, H, W, C")
sg.guard(labels, "B, 1") # raises error because of rank mismatch
sg.guard(flat_img, "B, H*W*C") # raises error because 1024 != 32*32*3
# guard also returns the tensor, so it can be inlined
mean_img = sg.guard(tf.reduce_mean(img, axis=0), "H, W, C")
# more readable reshapes
flat_img = sg.reshape(img, 'B, H*W*C')
# evaluate templates
assert sg['H, W*C+1'] == [32, 97]
# attribute access to inferred dimensions
assert sg.B == 64
Shape Template Syntax
The shape template mini-DSL supports many different ways of specifying shapes:
- numbers:
"64, 32, 32, 3"
- named dimensions:
"B, width, height2, channels"
- wildcards:
"B, *, *, *"
- ellipsis:
"B, ..., 3"
- addition, subtraction, multiplication, division:
"B*N, W/2, H*(C+1)"
- dynamic dimensions:
"?, H, W, C"
(only matches[None, H, W, C]
)
DISCLAIMER
This is not an officially supported Google product.
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
shapeguard-0.1.0.tar.gz
(29.2 kB
view details)
Built Distribution
File details
Details for the file shapeguard-0.1.0.tar.gz
.
File metadata
- Download URL: shapeguard-0.1.0.tar.gz
- Upload date:
- Size: 29.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.3 Linux/4.15.0-55-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2c3f64aa023904010242a9fc5e17082c0681408de7c58981345d694c83175e4 |
|
MD5 | 3d7d9c90a270711c1881a251ede7dfae |
|
BLAKE2b-256 | 855708fd164171dd0b7b12ef22cd1536d109023a506c67a78c583416614d2181 |
File details
Details for the file shapeguard-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: shapeguard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.17 CPython/3.7.3 Linux/4.15.0-55-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 915ac04985b1e29c4a2829d8bfd83abb3a96bd9eceafc776d6b3cca9646c9a22 |
|
MD5 | 49e606e3b7567b6612cd3dba1caddac6 |
|
BLAKE2b-256 | 2deebf5bc22c7cba09adc7c8e15f209860041c04407c1f2545523e6b1d32d198 |