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.
Metadata
Release files for shapeguard 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| shapeguard-0.1.1.tar.gz | 29.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| shapeguard-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.2 kB
Release files / shapeguard-0.1.1.tar.gz
| Download URL | shapeguard-0.1.1.tar.gz |
|---|---|
| Size | 29.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bd2a80a924acbf6d2fb07a6b2cbed742f7f9ecdfd77ee106ae5f48538abb31f
|
|
BLAKE2b-256 checksum How to use checksums |
4d44ce6a7100f94556aa4692cc9b150a0b909ed7470672ca6f72a9b23f324dea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.3 Linux/4.15.0-62-generic
|
Release files / shapeguard-0.1.1-py3-none-any.whl
| Download URL | shapeguard-0.1.1-py3-none-any.whl |
|---|---|
| Size | 32.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a489d6a8a33cdc6b6f4a2f7bf9e59d2824699373ca77b1c91ac12bb44b85b990
|
|
BLAKE2b-256 checksum How to use checksums |
e54c4991b4503ad19de7a8d3586f97d8dab3ecf59541e649bac5218dbcd294cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.3 Linux/4.15.0-62-generic
|
Security for shapeguard 0.1.1
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.