FB_VN_ReadNeuralNetwork
This FB reads a neural network from a file on the target pc.
Syntax
Definition:
FUNCTION_BLOCK FB_VN_ReadNeuralNetwork
VAR_INPUT
sFilePath : STRING;
ipDestNeuralNetwork : Reference To ITcVnNeuralNetwork;
aInputShape : Reference To TcVnArray33_UDINT;
bRead : BOOL;
nTimeout : TIME;
END_VAR
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrorId : UDINT;
END_VAR
Inputs
Name |
Type |
Default |
Description |
---|---|---|---|
sFilePath |
STRING |
|
Full path of the file or relative path to the default directory on the target pc |
ipDestNeuralNetwork |
Reference To ITcVnNeuralNetwork |
|
Returns the neural network |
aInputShape |
Reference To TcVnArray33_UDINT |
|
Optional input shape for testing the execution of the neural network model. The error code INCOMPATIBLE is returned if the execution fails. Setting aInputShape = 0 or aInputShape[0] = 0 disables the testing of the execution. |
bRead |
BOOL |
|
Reading the file is triggered by a rising edge at this input. |
nTimeout |
TIME |
VISION_ADS_TIMEOUT |
Indicates the time before the function is cancelled. |
Outputs
Name |
Type |
Description |
---|---|---|
bBusy |
BOOL |
This output remains TRUE until the function block has executed a command, but at the longest for the duration supplied to the 'nTimeout' input. While bBusy = TRUE, no new command will be accepted at the inputs. |
bError |
BOOL |
This output is switched to TRUE as soon as an error occurs during the execution of a command. The command-specific error code is contained in ‘nErrorId’. If the function block has a timeout error, 'bError' is TRUE and 'nErrorId' is 1861 (hexadecimal 0x745). Is reset to FALSE by the execution of a command at the inputs. |
nErrorId |
UDINT |
Contains the ADS error code or the command-specific error code of the last executed command. Is reset to 0 by the execution of a command at the inputs. |
Further information
The function block FB_VN_ReadNeuralNetwork
loads a neural network from a file asynchronously into the PLC. The file must be in the standardized exchange format Open Neural Network Exchange (ONNX), as only this format is supported.
Loading modified neural networks When loading a neural network, the Vision Service caches the data internally. Therefore, it is not possible to load modified neural networks in the standard system. To do this, adjust the Cache settings or see the sample Serial loading of images into the PLC for an alternative. |
Parameter
Some parameters are described centrally in the section File Access Parameters.
Loaded neural network (return value)
The loaded ITcVnNeuralNetwork
can be reached via the interface pointer ipDestNeuralNetwork
after a successful read process and optional test of the execution.
Testing the execution
The optional parameter aInputShape
can be used to transfer an input format that is used to test the execution of the neural network before loading it into the PLC. This test is helpful, especially for models with dynamic input formats, to ensure that the model can be successfully executed with the specified format. If the execution is not successful, a HRESULT = ADSERR_DEVICE_INCOMPATIBLE
is returned.
The following information can be used to specify an input format for the test, for example. The execution test can also be disabled with aInputShape[0] := 0;
.
aInputShape
[0] := 4;
aInputShape
[1] := 1;
aInputShape
[2] := 224;
aInputShape
[3] := 224;
aInputShape
[4] := 3;
Application
Loading a neural network, without testing the execution (aInputShape := 0;
), from the path C:\TcVision\NeuralNetwork.onnx
looks like this, for example:
fbReadNeuralNetwork
(
sFilePath := 'C:\TcVision\NeuralNetwork
.onnx',
ipDestNeuralNetwork
:= ipReadNeuralNetwork
,
aInputShape := 0;
bRead := TRUE,
nTimeout := T#500MS);
IF NOT fbReadNeuralNetwork
.bBusy AND NOT fbReadNeuralNetwork
.bError THEN
// Neural Network
is accessible in ipReadNeuralNetwork
END_IF
Required License
TC3 Vision Base
System Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT V3.1.4024.59 or later | PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU | Tc3_Vision |