DelphiPythonPython GUIWindows

Build An Artificial Intelligence Solutions With PyTorch Library In A Delphi Windows App

photo of woman holding a gray laptop in front of systems

Are you looking for an end-to-end open-source machine learning and deep learning platform, and build a nice GUI for them? You can deliver enterprise-grade AI solutions easily by combining PyTorch and Python4Delphi library, inside Delphi and C++Builder.

PyTorch is an open-source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing, primarily developed by Facebook’s AI Research lab (FAIR). It is free and open-source software released under the Modified BSD license. Although the Python interface is more polished and the primary focus of development, PyTorch also has a C++ interface.

A number of pieces of deep learning software are built on top of PyTorch, including Tesla Autopilot, Uber’s Pyro, HuggingFace’s Transformers, PyTorch Lightning, and Catalyst.

PyTorch provides two high-level features:

  • Tensor computing (like NumPy) with strong acceleration via graphics processing units (GPU)
  • Deep neural networks built on a tape-based automatic differentiation system

You can reuse your favorite Python packages such as NumPy, SciPy, and Cython to extend PyTorch when needed.

This post will guide you on how to run the PyTorch library and use Python for Delphi to display it in the Delphi Windows GUI app.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.




Let’s try to load and visualize the Fashion-MNIST dataset from TorchVision. Fashion-MNIST is a dataset of Zalando’s article images consisting of 60,000 training examples and 10,000 test examples. Each example comprises a 28×28 grayscale image and an associated label from one of 10 classes (0: “T-Shirt”,    1: “Trouser”,    2: “Pullover”, 3: “Dress”, 4: “Coat”, 5: “Sandal”, 6: “Shirt”, 7: “Sneaker”, 8: “Bag”, 9: “Ankle Boot”).


Pretty cool, right?

As performed with TensorFlow in our previous posts, the performance of PyTorch combined with Python4Delphi is much faster compared with regular Python!

See the long iterations of the exact same code, performed in IDE without integrations with Python4Delphi:



Congratulations, now you have learned how to run the PyTorch library and use Python for Delphi to display it in the Delphi Windows GUI app! Now you can try lots more sophisticated examples from these documentations using the PyTorch library and Python4Delphi.

Check out the PyTorch library for Python and use it in your projects: and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi:

Related posts
Learn PythonPythonPython GUIVideos

How To Make Your Data Visualization Effective

DelphiDelphiVCLPythonPython GUIWindows

This Is A List Of All Routines And Classes in the VCL

DelphiDelphiVCLPythonPython GUIWindows

What is DelphiVCL.Application.CreateHandle?

DelphiDelphiVCLPythonPython GUIWindows

Creating A New Application With DelphiVCL.Application.Create

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *