Skip to main content

TensorGuard helps to guard against bad Tensor Shapes

Project description

Tensor Guard

tensorguard logo

PyPI version fury.io PyPI pyversions PyPI download month GitHub followers


TensorGuard helps to guard against bad Tensor shapes in any tensor based library (e.g. Numpy, Pytorch, Tensorflow) using an intuitive symbolic-based syntax

Installation

pip install tensorguard

Basic Usage

import numpy as np  # could be tensorflow or torch as well
import tensorguard as tg

# tensorguard = tg.TensorGuard()  #could be done in a OOP fashion
img = np.ones([64, 32, 32, 3])
flat_img = np.ones([64, 1024])
labels = np.ones([64])

# check shape consistency
tg.guard(img, "B, H, W, C")
tg.guard(labels, "B, 1")  # raises error because of rank mismatch
tg.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 = tg.guard(np.mean(img, axis=0), "H, W, C")

# more readable reshapes
flat_img = tg.reshape(img, 'B, H*W*C')

# evaluate templates
assert tg.get_dims('H, W*C+1') == [32, 97]

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])

Original Repo link: https://github.com/Qwlouse/shapeguard

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

tensorguard-1.0.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

tensorguard-1.0.1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file tensorguard-1.0.1.tar.gz.

File metadata

  • Download URL: tensorguard-1.0.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tensorguard-1.0.1.tar.gz
Algorithm Hash digest
SHA256 97587d9f48435edd029923fb0c1bb2e852bca1e12f0356b5d20b3d71273e6b28
MD5 999304e569d617d7bf8ad72818107ab1
BLAKE2b-256 1b1471faf13ca1cc9eb2a130b4d6558f814855fcfebe45e81cb3f698cb2c52fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for tensorguard-1.0.1.tar.gz:

Publisher: publish-to-pypi.yml on Michedev/tensorguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tensorguard-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: tensorguard-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tensorguard-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0fd807343b3a0588f202be3e483781c99ce92b67760c41d32ea992079889636a
MD5 afc20dc267f6f737f20075daae6c1da3
BLAKE2b-256 1ad55cbc7a753752a2a514b08427d0617d43e8eb2fc28cae9af0ba6390276115

See more details on using hashes here.

Provenance

The following attestation bundles were made for tensorguard-1.0.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Michedev/tensorguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page