Skip to main content

Practical Pipelining for pyTorch

Project description

Torch Tensor Types

This package is a Quality of Life improvement when prototyping and processing Tensor objects from the pyTorch library. The TensorType class is a Pipeline for preprocessing tensors automatically, and include multiple utility methods. my_TensorType<<myData You can add TensorTypes together to have a longer preprocessing pipeline. myTensorType + myOtherTensorType

For example, this code

fake_image = model(torch.unsqueeze(real_image, 0).cuda()).cpu().detach().numpy()[0]

can be replaced by

fake_image = SingleDisplayableImage<<model(ModelInputFormat<<real_image)

The list of arguments to the constructor is:

TensorType:
__init__(shape=None, transforms=[], torch_methods=[],
to_batch=False, device=None, from_single_value=False,
random_values=False, to_numpy=False, detach=False):

All of these should be pretty telling by their name, if you know pyTorch.

  • TensorType.shape: the input will be viewed as this shape
  • TensorType.transforms: a list of functions that will be applied at the end
  • TensorType.torch_methods: a list of method names that will be called on the tensor i.e "mean" => tensor.mean()
  • TorchType.to_batch: will unsqueeze the data into a batch with a single sample
  • TorchType.device: transfers the tensor to a device
  • TorchType.from_single_value: creates a uniform tensor from a single value
  • TorchType.random_values: creates a tensor from torch.rand
  • TensorType.to_numpy: outputs a numpy array
  • TensorType.detach: detachs the tensor from the graph

Syntax

from TTT import TensorType as TT
# Creates a uniform image tensor pipeline
myTensorType = TT(shape=(3, 224, 224), from_single_value=True)
# A black image
data = myTensorType<<0
# "myTensorType" will parse first, then the other TT
myDisplayableImage = myTensorType + TT(to_numpy=True, transforms=[np.transpose])
# A white image ready to display
myDisplayableImage<<1

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

torch-tensor-type-0.1.1.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

torch_tensor_type-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file torch-tensor-type-0.1.1.tar.gz.

File metadata

  • Download URL: torch-tensor-type-0.1.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for torch-tensor-type-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a8e4d4d79c0d4761f8d3c0b0416fec05bd9cf287baa60eb9807fe292986fc24e
MD5 d82c8634f5f74d8ada272beff4602735
BLAKE2b-256 069493b4cf8eafba5d8f7a0d49e7e4f1cb98c5c42365b1f304e25344d5ab0668

See more details on using hashes here.

File details

Details for the file torch_tensor_type-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: torch_tensor_type-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for torch_tensor_type-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5e218a91a4b0d4fa6928c33c337d71874510116490eea9b1ff8606242fc5e93
MD5 c36a9e0bae74f532bc4e57e04c93d9be
BLAKE2b-256 5fcdaaafd66ddc8e12c4696df6a656e7ece3ad3d5baf6583e6441a9ded1afada

See more details on using hashes here.

Supported by

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