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
DelphiDelphiVCLPythonPython GUIWindows

Learn about the DelphiVCL.Component as the Common Ancestor of All Component Classes

Learn PythonPythonVideos

Learn Python With The Hidden Power of the Python Runtime by Elizaveta Shashkova (PyCon 2020) Videos

Learn PythonPythonVideos

Learn Python With Organizing to Improve Your Workplace: Know Your Rights by Shauna Gordon-McKeon (PyCon 2020) Video

DelphiPythonPython GUIWindows

Learn To Build A Python GUI For Manipulating Datetime Using Delorean Library In A Delphi Windows App

Leave a Reply

Your email address will not be published. Required fields are marked *