FB_VN_ReadMlModel

FB_VN_ReadMlModel 1:

This FB reads a machine learning model from a file on the target pc.

Syntax

Definition:

FUNCTION_BLOCK FB_VN_ReadMlModel
VAR_INPUT
    sFilePath     : STRING;
    ipDestMlModel : Reference To ITcVnMlModel;
    bRead         : BOOL;
    nTimeout      : TIME;
END_VAR
VAR_OUTPUT
    bBusy         : BOOL;
    bError        : BOOL;
    nErrorId      : UDINT;
END_VAR

FB_VN_ReadMlModel 2: Inputs

Name

Type

Default

Description

sFilePath

STRING

 

Full path of the file or relative path to the default directory on the target pc

ipDestMlModel

Reference To ITcVnMlModel

 

Returns the loaded machine learning model

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.

FB_VN_ReadMlModel 3: 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.

Weiterführende Informationen

Der Funktionsblock FB_VN_ReadMlModel lädt ein ML-Modell aus einer Datei asynchron in die SPS.

FB_VN_ReadMlModel 4:

Laden von geänderten ML-Modellen

Beim Einladen des ML-Modells cached der Vision-Service die Daten intern. Ein Einladen von geänderten ML-Modellen ist somit im Standard nicht möglich. Passen Sie dazu die die Cache Einstellungen an oder sehen Sie das Beispiel Serielles Laden von Bildern in die SPS für eine Alternative.

Parameter

Einige Parameter sind zentral im Kapitel File Access Parameter beschrieben.

Geladenes ML-Modell (Rückgabewert)

Das geladene ITcVnMlModel ist nach erfolgreichem Lesevorgang über den Interface Pointer ipDestMlModel zu erreichen.

Einen Sonderfall stellt die Verwendung als ITcVnColorModel dar, da nach dem Laden des Modells noch eine Umwandlung mit folgender Zeile erforderlich ist. Alternativ kann das ITcVnMlModel auch mit den entsprechenden Funktionen direkt weiterverwendet werden.

hr := ipReadMlModel.TcQueryInterface(IID_ITcVnColorModel, ADR(ipColorModel));

Anwendung

Das Laden eines ML-Modells vom Pfad C:\TcVision\MlModel.vmlm sieht z. B. so aus:

fbReadMlModel(
    sFilePath       := 'C:\TcVision\MlModel.vmlm',
    ipDestMlModel   := ipReadMlModel,
    bRead           := TRUE,
    nTimeout        := T#500MS);

IF NOT fbReadMlModel.bBusy AND NOT fbReadMlModel.bError THEN
    // Ml-Model is accessible in ipReadMlModel
END_IF

Verwandter Funktionsblock: FB_VN_WriteMlModel.

Required License

TC3 Vision Base

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1. 4024.44 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision