UNeuralNetwork

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

NeuralNetworkInference

Header

/Engine/Plugins/Experimental/NeuralNetworkInference/Source/NeuralNetworkInference/Public/NeuralNetwork.h

Include

#include "NeuralNetwork.h"

Syntax

UCLASS(BlueprintType)
class UNeuralNetwork : public UObject

Variables

Name Description

Protected variable UProperty Category, EditAnywhere

ENeuralDeviceTy...

 

DeviceType

The neural device type of the network.

Protected variable UProperty Category, EditAnywhere

ENeuralDeviceTy...

 

InputDeviceType

It defines whether Run() will expect the input data in CPU memory (Run will upload the memory to the GPU) or GPU memory (no upload needed).

Protected variable UProperty Category visibleanywhere

FString

 

ModelFullFilePath

Original model file path from which this UNeuralNetwork was loaded from.

Protected variable UProperty Category, EditAnywhere

ENeuralDeviceTy...

 

OutputDeviceType

It defines whether Run() will return the output data in CPU memory (Run will download the memory to the CPU) or GPU (no download needed).

Protected variable UProperty Category, EditAnywhere Transient

ENeuralSynchron...

 

SynchronousMode

It defines whether UNeuralNetwork::Run() will block the thread until completed (Synchronous), or whether it will run on a background thread, not blocking the calling thread (Asynchronous).

Protected variable UProperty Category, EditAnywhere Transient

ENeuralThreadMo...

 

ThreadModeDelegateForAsyncRunCompleted

If SynchronousMode is Asynchronous, this variable will define whether the callback delegate is called from the game thread (highly recommended) or from any available thread (not fully thread safe).

Constructors

Name Description

Public function

UNeuralNetwork()

Default constructor that initializes the internal class variables.

Destructors

Name Description

Public function Virtual

~UNeuralNetwork()

Destructor defined in case this class is ever inherited.

Functions

Name Description

Public function

 

DECLARE_DELEGATE

(
    FOnAsyncRunCompleted
)

FOnAsyncRunCompleted is the delegate that gets triggered when an asynchronous inference has been completed (i.e., Run() was called with NeuralSynchronousMode == ENeuralSynchronousMode::Asynchronous).

Public function

TObjectPtr< ...

 

GetAndMaybeCreateAssetImportData()

Public function Const

TObjectPtr< ...

 

GetAssetImportData()

Internal and Editor-only functions not needed by the user.

Public function Const

ENeuralBackE...

 

GetBackEnd()

Internal functions that should not be used by the user.

Public function Const

ENeuralDevic...

 

GetDeviceType()

Getter and setter functions for DeviceType, InputDeviceType, and OutputDeviceType:

Public function

void *

 

GetInputDataPointerMutable

(
    const int32 InTensorIndex
)

Public function Const

ENeuralDevic...

 

GetInputDeviceType()

Public function Const

FNeuralStati...

 

GetInputMemoryTransferStats()

Public function Const

const FNeura...

 

GetInputTensor

(
    const int32 InTensorIndex
)

GetInputTensor() and GetOutputTensor() return a const (read-only) reference of the input or output FNeuralTensor(s) of the network, respectively.

Public function Const

int64

 

GetInputTensorNumber()

GetInputTensorNumber() and GetOutputTensorNumber() return the number of input or output tensors of this network, respectively.

Public function Const

float

 

GetLastRunTimeMSec()

Statistics-related functions:

Public function

FOnAsyncRunC...

 

GetOnAsyncRunCompletedDelegate()

Public function Const

ENeuralDevic...

 

GetOutputDeviceType()

Public function Const

const FNeura...

 

GetOutputTensor

(
    const int32 InTensorIndex
)

Public function Const

int64

 

GetOutputTensorNumber()

Public function Const

FNeuralStati...

 

GetRunStatistics()

Public function Const

ENeuralSynch...

 

GetSynchronousMode()

Getter and setter functions for SynchronousMode:

Public function Const

ENeuralThrea...

 

GetThreadModeDelegateForAsyncRunCompleted()

Getter and setter functions for ThreadModeDelegateForAsyncRunCompleted:

Public function

void

 

InputTensorsToGPU

(
    const TArray< int32 >& InTensorInd...
)

Non-computationally-efficient functions meant to be used only for debugging purposes, but should never be used on highly performant systems:

Public function Const

bool

 

IsGPUSupported()

Whether GPU execution (i.e., SetDeviceType(ENeuralDeviceType::GPU)) is supported for this platform:

Public function Const

bool

 

IsLoaded()

It returns whether a network is currently loaded. It is equivalent to the output of Load().

Public function

bool

 

Load

(
    const FString& InModelFilePath
)

Load() + SetInputFromArrayCopy() + Run() is the simplest way to load an ONNX file, set the input tensor(s), and run inference on it.

Public function

bool

 

Load

(
    TArray< uint8 >& InModelReadFromFi...
)

Load() + SetInputFromArrayCopy() + Run() is the simplest way to load an ONNX file, set the input tensor(s), and run inference on it.

Public function

bool

 

Load

(
    TArray< FNeuralTensor >& InTensors,
    const TArray< FNeuralTensor* >...,
    const TArray< FNeuralTensor* >...,
    const TArray< TSharedPtr< class FNe...
)

Internal function not needed by the user.

Public function

void

 

OutputTensorsToCPU

(
    const TArray< int32 >& InTensorInd...
)

Public function

void

 

ResetStats()

Public function

void

 

Run()

Load() + SetInputFromArrayCopy() + Run() is the simplest way to load an ONNX file, set the input tensor(s), and run inference on it.

Public function

void

 

SetDeviceType

(
    const ENeuralDeviceType InDeviceTyp...,
    const ENeuralDeviceType InInputDevi...,
    const ENeuralDeviceType InOutputDev...
)

Public function

void

 

SetInputFromArrayCopy

(
    const TArray< float >& InArray,
    const int32 InTensorIndex
)

SetInputFromArrayCopy(), SetInputFromVoidPointerCopy(), and GetInputDataPointerMutable() are the only functions that allow modifying the network input tensor(s) values:

Public function

void

 

SetInputFromVoidPointerCopy

(
    const void*const InVoidPtr,
    const int32 InTensorIndex
)

Public function

void

 

SetSynchronousMode

(
    const ENeuralSynchronousMode InSync...
)

Public function

void

 

SetThreadModeDelegateForAsyncRunCompleted

(
    const ENeuralThreadMode InThreadMod...
)

Classes

Enums

Name

Description

Public enum

ENeuralBackEnd

Internal enum class that should not be used by the user.

Deprecated Functions

Name Description

Public function Const

ENeuralBackE...

 

GetBackEndForCurrentPlatform()

Do not use, ENeuralBackEnd will be removed in future versions and only UEAndORT back end will be supported.

Public function

bool

 

SetBackEnd

(
    const ENeuralBackEnd InBackEnd
)

Do not use, ENeuralBackEnd will be removed in future versions and only UEAndORT back end will be supported.