| Name | tensor-visualizer JSON |
| Version |
0.1.0
JSON |
| download |
| home_page | None |
| Summary | A Jupyter widget for visualizing tensors as heatmaps. |
| upload_time | 2024-08-27 22:36:30 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.7 |
| license | Copyright © 2024 Apple Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
SOFTWARE DISTRIBUTED WITH tensor-visualizer:
The tensor-visualizer software includes a number of subcomponents with separate
copyright notices and license terms - please see the file ACKNOWLEDGEMENTS.
------------------------------------------------------------------------------- |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Tensor Visualizer
This is a package to visualize tensor data in notebooks.
<img src="https://raw.githubusercontent.com/apple/tensor-visualizer/main/assets/screenshot.png" width="512px" alt="the TensorVisualizer widget" />
## Install
```bash
pip install tensor-visualizer
```
## Usage
You can use this widget in a notebook to visualize tensor data.
The widget supports numpy `ndarray`s, PyTorch and Tensorflow tensors,
as well as MLX tensors.
```python
from tensor_visualizer import TensorVisualizer
# Visualize a 4-dimensional numpy array.
import numpy as np
data = np.random.randn(5, 10, 10, 10)
widget = TensorVisualizer(data)
widget
```
```python
from tensor_visualizer import TensorVisualizer
# Visualize a 4-dimensional torch tensor.
import torch
data = torch.randn((5, 10, 10, 10))
widget = TensorVisualizer(data)
widget
```
You can name dimensions with the `names` argument:
```python
TensorVisualizer(data, names=["batch", "channel", "height", "width"])
```
and label indices for the dimensions with the `labels` argument:
```python
TensorVisualizer(
data,
names=["batch", "channel", "height", "width"],
labels=[["b1", "b2", "b3"], ["ch1", "ch2"]]
)
```
By default the widget infers the color scale automatically from your data. To configure the color scale, you can set the `scale_domain`, `scale_type`, and `scale_scheme` properties:
```python
# Set the scale domain to [1, 100], log scale,
# and use the viridis color scheme.
w = TensorVisualizer(data, scale_domain=[1, 100], scale_type="log", scale_scheme="viridis")
# You can also set it after creating the widget
w.scale_domain = [0, 1]
```
If you are using inferred scales, you can access the inferred scale properties with `current_scale_domain`, `current_scale_type`, and `current_scale_scheme`. These properties are available only after the widget has been shown.
You may use the `permute` argument the re-order the tensor dimensions in the visualization. For instance, `permute=[2, 0, 1, 3]` shows dimension 2 first, then dimension 0, 1, and 3. The last two dimensions are used in the heatmap.
### Parameters
| Name | Description |
| --------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `tensor` | The tensor to visualize. |
| `names` | The names for dimensions in the tensor. |
| `labels` | Lists of labels for dimensions in the tensor. |
| `default_views` | Specify the default views for each dimension, supported options are: `slice`, `small-multiples`, `min`, `max`, and `mean`. |
| `scale_domain` | Specify the scale domain. If unspecified, the widget will infer the domain automatically. |
| `scale_type` | Specify the scale type (linear or log). The default is linear. |
| `scale_scheme` | Specify the scale color scheme. If unspecified, the widget will infer the scheme automatically. |
| `permute` | Permute the order of the tensor's dimensions. |
## Development
This project consists of a Svelte library for the frontend component, and Python code for the widget.
To setup for frontend development, run:
```bash
npm install
npm run dev
```
You'll get a development server (usually at <http://localhost:5173>)
that hosts an demo page of the frontend component.
To build the frontend package, run:
```bash
npm run build
```
To build the Python package, run:
```bash
hatch build
```
To develop the widget, you can start a Jupyter Lab instance and load the example notebooks in the `examples` folder:
```bash
hatch run jupyter lab
```
Raw data
{
"_id": null,
"home_page": null,
"name": "tensor-visualizer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Donghao Ren <donghao@apple.com>",
"download_url": "https://files.pythonhosted.org/packages/4c/a4/0ec318fd2e79d4c7b2b6b85d8e8fb0934b496debf10d12dbd5d0c38b9f6a/tensor_visualizer-0.1.0.tar.gz",
"platform": null,
"description": "# Tensor Visualizer\n\nThis is a package to visualize tensor data in notebooks.\n\n<img src=\"https://raw.githubusercontent.com/apple/tensor-visualizer/main/assets/screenshot.png\" width=\"512px\" alt=\"the TensorVisualizer widget\" />\n\n## Install\n\n```bash\npip install tensor-visualizer\n```\n\n## Usage\n\nYou can use this widget in a notebook to visualize tensor data.\nThe widget supports numpy `ndarray`s, PyTorch and Tensorflow tensors,\nas well as MLX tensors.\n\n```python\nfrom tensor_visualizer import TensorVisualizer\n\n# Visualize a 4-dimensional numpy array.\nimport numpy as np\ndata = np.random.randn(5, 10, 10, 10)\nwidget = TensorVisualizer(data)\nwidget\n```\n\n```python\nfrom tensor_visualizer import TensorVisualizer\n\n# Visualize a 4-dimensional torch tensor.\nimport torch\ndata = torch.randn((5, 10, 10, 10))\nwidget = TensorVisualizer(data)\nwidget\n```\n\nYou can name dimensions with the `names` argument:\n\n```python\nTensorVisualizer(data, names=[\"batch\", \"channel\", \"height\", \"width\"])\n```\n\nand label indices for the dimensions with the `labels` argument:\n\n```python\nTensorVisualizer(\n data,\n names=[\"batch\", \"channel\", \"height\", \"width\"],\n labels=[[\"b1\", \"b2\", \"b3\"], [\"ch1\", \"ch2\"]]\n)\n```\n\nBy default the widget infers the color scale automatically from your data. To configure the color scale, you can set the `scale_domain`, `scale_type`, and `scale_scheme` properties:\n\n```python\n# Set the scale domain to [1, 100], log scale,\n# and use the viridis color scheme.\nw = TensorVisualizer(data, scale_domain=[1, 100], scale_type=\"log\", scale_scheme=\"viridis\")\n# You can also set it after creating the widget\nw.scale_domain = [0, 1]\n```\n\nIf you are using inferred scales, you can access the inferred scale properties with `current_scale_domain`, `current_scale_type`, and `current_scale_scheme`. These properties are available only after the widget has been shown.\n\nYou may use the `permute` argument the re-order the tensor dimensions in the visualization. For instance, `permute=[2, 0, 1, 3]` shows dimension 2 first, then dimension 0, 1, and 3. The last two dimensions are used in the heatmap.\n\n### Parameters\n\n| Name | Description |\n| --------------- | -------------------------------------------------------------------------------------------------------------------------- |\n| `tensor` | The tensor to visualize. |\n| `names` | The names for dimensions in the tensor. |\n| `labels` | Lists of labels for dimensions in the tensor. |\n| `default_views` | Specify the default views for each dimension, supported options are: `slice`, `small-multiples`, `min`, `max`, and `mean`. |\n| `scale_domain` | Specify the scale domain. If unspecified, the widget will infer the domain automatically. |\n| `scale_type` | Specify the scale type (linear or log). The default is linear. |\n| `scale_scheme` | Specify the scale color scheme. If unspecified, the widget will infer the scheme automatically. |\n| `permute` | Permute the order of the tensor's dimensions. |\n\n## Development\n\nThis project consists of a Svelte library for the frontend component, and Python code for the widget.\n\nTo setup for frontend development, run:\n\n```bash\nnpm install\nnpm run dev\n```\n\nYou'll get a development server (usually at <http://localhost:5173>)\nthat hosts an demo page of the frontend component.\n\nTo build the frontend package, run:\n\n```bash\nnpm run build\n```\n\nTo build the Python package, run:\n\n```bash\nhatch build\n```\n\nTo develop the widget, you can start a Jupyter Lab instance and load the example notebooks in the `examples` folder:\n\n```bash\nhatch run jupyter lab\n```\n",
"bugtrack_url": null,
"license": "Copyright \u00a9 2024 Apple Inc. All rights reserved.\n \n Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n \n 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n \n 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n \n 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n \n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \u201cAS IS\u201d AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n \n -------------------------------------------------------------------------------\n SOFTWARE DISTRIBUTED WITH tensor-visualizer:\n \n The tensor-visualizer software includes a number of subcomponents with separate \n copyright notices and license terms - please see the file ACKNOWLEDGEMENTS.\n -------------------------------------------------------------------------------",
"summary": "A Jupyter widget for visualizing tensors as heatmaps.",
"version": "0.1.0",
"project_urls": {
"homepage": "https://github.com/apple/tensor-visualizer"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d701c895ba3966f7f0d8d1efb68fbb65b6d4ff53a5b4124e328e8d49a46382f9",
"md5": "8d5a956302a132ad06c78845d4bba3d3",
"sha256": "b7bdeacef9b443403b3712f6c4b6279c122034d4b296a7768197a275f2d0f871"
},
"downloads": -1,
"filename": "tensor_visualizer-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8d5a956302a132ad06c78845d4bba3d3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 58160,
"upload_time": "2024-08-27T22:36:28",
"upload_time_iso_8601": "2024-08-27T22:36:28.740324Z",
"url": "https://files.pythonhosted.org/packages/d7/01/c895ba3966f7f0d8d1efb68fbb65b6d4ff53a5b4124e328e8d49a46382f9/tensor_visualizer-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4ca40ec318fd2e79d4c7b2b6b85d8e8fb0934b496debf10d12dbd5d0c38b9f6a",
"md5": "229f6ec74923a3188823a7bdd958f782",
"sha256": "01b7f5b82a6dd19b7f56b206c38dd48ea9b773c6de2a6413a6bacef8b3b367db"
},
"downloads": -1,
"filename": "tensor_visualizer-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "229f6ec74923a3188823a7bdd958f782",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 172461,
"upload_time": "2024-08-27T22:36:30",
"upload_time_iso_8601": "2024-08-27T22:36:30.352795Z",
"url": "https://files.pythonhosted.org/packages/4c/a4/0ec318fd2e79d4c7b2b6b85d8e8fb0934b496debf10d12dbd5d0c38b9f6a/tensor_visualizer-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-27 22:36:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "apple",
"github_project": "tensor-visualizer",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tensor-visualizer"
}