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
356 stars 195 forks source link

Porting all code for Delphi user #17

Closed Pigrecos closed 4 years ago

Pigrecos commented 4 years ago

basic test with delphi 10.3

joaopauloschuler commented 4 years ago

Interesting request! I'll review it with care.

joaopauloschuler commented 4 years ago

Example continues to work after merge: https://colab.research.google.com/github/joaopauloschuler/neural-api/blob/master/examples/SimpleImageClassifierGPU/SimpleImageClassifierGPU.ipynb

joaopauloschuler commented 4 years ago

Doesn't work for me. You can test with:

  var
    NN: THistoricalNets;
    NeuralFit: TNeuralImageFit;
    ImgTrainingVolumes, ImgValidationVolumes, ImgTestVolumes: TNNetVolumeList;
  begin
    if not CheckCIFARFile() then exit;
    WriteLn('Creating Neural Network...');
    NN := THistoricalNets.Create();
    NN.AddLayer([
      TNNetInput.Create(32, 32, 3),
      TNNetConvolutionLinear.Create(32, 5, 2, 1, 1).InitBasicPatterns(),
      TNNetMaxPool.Create(4),
      TNNetConvolutionReLU.Create(32, 3, 1, 1, 1),
      TNNetConvolutionReLU.Create(32, 3, 1, 1, 1),
      TNNetDropout.Create(0.5),
      TNNetMaxPool.Create(2),
      TNNetFullConnectLinear.Create(10),
      TNNetSoftMax.Create()
    ]);
    CreateCifar10Volumes(ImgTrainingVolumes, ImgValidationVolumes, ImgTestVolumes);

    NeuralFit := TNeuralImageFit.Create;
    NeuralFit.FileNameBase := 'SimpleImageClassifier';
    NeuralFit.InitialLearningRate := 0.001;
    NeuralFit.LearningRateDecay := 0.99;
    NeuralFit.StaircaseEpochs := 10;
    NeuralFit.Inertia := 0.9;
    NeuralFit.L2Decay := 0.00001;

    {$ifdef OpenCL}
    InitOpenCL;
    WriteLn('Creating TEasyOpenCL.');
    FEasyOpenCL := TEasyOpenCL.Create();
    WriteLn('Detecting Platforms.');
    if FEasyOpenCL.GetPlatformCount() > 0 then
    begin
      WriteLn('Setting platform to: ', FEasyOpenCL.PlatformNames[0]);
      FEasyOpenCL.SetCurrentPlatform(FEasyOpenCL.PlatformIds[0]);
      if FEasyOpenCL.GetDeviceCount() > 0 then
      begin
        WriteLn('Setting device to: ', FEasyOpenCL.DeviceNames[0]);
        NeuralFit.EnableOpenCL(FEasyOpenCL.PlatformIds[0], FEasyOpenCL.Devices[0]);
      end
      else
      begin
        WriteLn('No OpenCL device has been found.');
      end;
    end
    else
    begin
      WriteLn('No OpenCL platform has been found.');
    end;
    {$endif}

    NeuralFit.Fit(NN, ImgTrainingVolumes, ImgValidationVolumes, ImgTestVolumes, {NumClasses=}10, {batchsize=}128, {epochs=}50);

    {$ifdef OpenCL}
    FEasyOpenCL.Free;
    {$endif}

    NeuralFit.Free;
    NN.Free;
    ImgTestVolumes.Free;
    ImgValidationVolumes.Free;
    ImgTrainingVolumes.Free;
  end;
joaopauloschuler commented 4 years ago

FIXED!

Pigrecos commented 4 years ago

FIXED!

Great, Delphi has problems with 'inline Directive' and Open Array.

joaopauloschuler commented 4 years ago

Yes. I fixed inlines too.