joaopauloschuler / neural-api

CAI NEURAL API - Pascal based deep learning neural network API optimized for AVX, AVX2 and AVX512 instruction sets plus OpenCL capable devices including AMD, Intel and NVIDIA.
GNU Lesser General Public License v2.1
371 stars 198 forks source link

Callback for write on screen (WriteLn) #48

Open davaponte opened 3 years ago

davaponte commented 3 years ago

It would be nice to provide a callback function to print the output messages in a GUI. For example, a TMemo. I mean the ones that are written with WriteLn.

For example:

  WriteLn
  (
    'Min/Max at 0:',  Min0:4:0,' ',Max0:4:0,
    ' at 1:', Min1:4:0,' ',Max1:4:0,
    ' at 2:', Min2:4:0,' ',Max2:4:0
  );

will be

S := Format('Min/Max at 0: %4.0f %4.0f at 1: %4.0f %4.0f at 2: %4.0f %4.0f', 
           [Min0, Max0, Min1, Max1, Min2, Max2]); 
SomeCallBack(S);

and, by default SomeCallBack point to a simple procedure with a WriteLn to don't break anything

procedure SomeCallBack(S: string);
begin
  WriteLn(S);
end;
joaopauloschuler commented 3 years ago

Hello! In the case that you are using NeuralFit, it descents from TMObject. TMObject does what you are asking for:

  TMObject = class(TObject)
    protected
      FMessageProc: TGetStrProc;
      FErrorProc: TGetStrProc;

    public
      constructor Create(); virtual;
      destructor Destroy(); override;

      procedure DefaultMessageProc(const S: string);
      procedure DefaultErrorProc(const S: string);
      procedure DefaultHideMessages(const S: string);
      procedure HideMessages();

    published
      property MessageProc: TGetStrProc read FMessageProc write FMessageProc;
      property ErrorProc: TGetStrProc read FErrorProc write FErrorProc;
  end;

You can just attribute new functions to MessageProc and to ErrorProc. TNNetNeuron, TNNetLayer and TNNet also descend from TMObject. Let me know please if there are additional messages that you would like covered by TMObject.

joaopauloschuler commented 3 years ago

There is an example here: https://github.com/joaopauloschuler/neural-api#got-too-many-console-messages

joaopauloschuler commented 3 years ago

@davaponte , please confirm areas that you need writeln replaced first. So far, all fitting writelns (except for csv creation) have been replaced.