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 script 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.

0 rundemo1 6813476

 

Demo

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“).

3 4550857

Pretty cool, right?

As performed with TensorFlow in our previous post, 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:

1pyscripter 8038908

 

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: https://pypi.org/project/torch/ and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi

References & further readings

[1] PyTorch Documentation. (2023). Datasets & dataloaders. The PyTorch Foundation, The Linux Foundation. pytorch.org/tutorials/beginner/basics/data_tutorial.html

[2] PyTorch Documentation. (2023). Get started: Start locally. The PyTorch Foundation, The Linux Foundation. pytorch.org/get-started/locally

[3] Xiao, H., Rasul, K., & Vollgraf, R. (2017). Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms. arXiv preprint arXiv:1708.07747.

[4] Zalando Research. (2022). Fashion-MNIST. GitHub repository. github.com/zalandoresearch/fashion-mnist

Related posts
CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And OpenCV Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Radial Basis Function Networks (RBFNs)

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

Leave a Reply

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