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 shapeTensorType.transforms: a list of functions that will be applied at the endTensorType.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 sampleTorchType.device: transfers the tensor to a deviceTorchType.from_single_value: creates a uniform tensor from a single valueTorchType.random_values: creates a tensor fromtorch.randTensorType.to_numpy: outputs a numpy arrayTensorType.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
Metadata
Release files for torch-tensor-type 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torch-tensor-type-0.1.2.tar.gz | 2.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torch_tensor_type-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.9 kB
Release files / torch-tensor-type-0.1.2.tar.gz
| Download URL | torch-tensor-type-0.1.2.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54010fad254f37454a70c6cf1a1411a1eb740393074455634e41a68d884f94f5
|
|
BLAKE2b-256 checksum How to use checksums |
7beb5361baf6f788339cdb6f0a8afd961eb512c29f38a59bd9befbb87b949ac5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / torch_tensor_type-0.1.2-py3-none-any.whl
| Download URL | torch_tensor_type-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c54e98af81c935cac846e2ce7cbbb7396bd25ef58dca03548255b12e3498b9f
|
|
BLAKE2b-256 checksum How to use checksums |
143e2e8e487a3f1a4c2a6f28183b782a2433153f915f04baea4bfd821843ef79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|