docs.unity3d.com
Search Results for

    Show / Hide Table of Contents
    Note

    Sentis is now called Inference Engine. The documentation has moved to https://docs.unity3d.com/Packages/com.unity.ai.inference@latest. Refer to the new location for the latest updates and guidance. Make sure to update your bookmarks and references accordingly.

    Tensor fundamentals in Sentis

    In Sentis, data is input and output using multi-dimensional arrays called tensors. These tensors function similarly to those in TensorFlow, PyTorch, and other machine learning frameworks.

    Tensors can have up to eight dimensions. If a tensor has zero dimensions, it contains a single value called a scalar.

    You can create the following types of tensor:

    • Tensor<float>, which stores the data as floats.
    • Tensor<int>, which stores the data as ints.

    For more information, refer to Create and modify tensors.

    Memory layout

    Sentis stores tensors in memory in row-major order, so the values of the last dimension are stored adjacently.

    Here's an example of a 2 × 2 × 3 tensor with the values 0 to 11 and how Sentis stores the tensor in memory.

    Format

    A model usually needs an input tensor in a certain format. For example, a model that processes images might need a 3-channel 240 × 240 image in one of the following formats:

    • 1 × 240 × 240 × 3, where the order of the dimensions is batch size, height, width, channels (NHWC)
    • 1 × 3 × 240 × 240, where the order of the dimensions is batch size, channels, height, width (NCHW)

    If your tensor doesn't match the format the model needs, you might get unexpected results.

    You can use the Sentis functional API to convert a tensor to a different format. For more information, refer to Edit a model.

    To convert a texture to a tensor in a specific format, refer to Create input for a model.

    Memory location

    Sentis stores tensor data in either graphics processing unit (GPU) memory or central processing unit (CPU) memory, depending on the backend type you select. For example, if you use the BackendType.GPUCompute backend type, tensors are typically stored in GPU memory.

    Directly reading from and writing to tensor elements is only possible when the tensor is on the CPU, which can be slow. For better performance, it's more efficient to modify your model using the functional API.

    To prevent Sentis from performing a blocking readback and upload, use a compute shader, Burst, or a native array. This allows you to read from and write to the tensor data directly in memory. For more information, refer to Access tensor data directly.

    When you need to read an output tensor, perform an asynchronous readback. This prevents Sentis from blocking the main code thread while waiting for the model to finish and download the entire tensor. For more information, refer to Read output from a model asynchronously.

    Additional resources

    • Understand the Sentis workflow
    • Understand models in Sentis
    • Create and modify tensors

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Memory layout
    • Format
    • Memory location
    • Additional resources
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)