Table of Contents
How do I start using Machine Learning in Windows?
Machine learning isn’t just for the cloud, or run locally in a web browser or command prompt. Microsoft is bringing it to PCs in the latest Windows 10 release. For example, Microsoft provides Python’s WinRT to create Windows Machine Learning applications, and ONNX (Open Neural Network Exchange) format, an open standard for sharing trained deep learning models between platforms and services [1].
The latest release of Windows 10 provides plenty of new APIs for your applications. This includes support for running trained Machine Learning models as part of Windows applications, taking advantage of local GPUs to accelerate Machine Learning applications.
On the other hand, Python4Delphi (P4D) empowers Python users with Delphi’s award-winning VCL functionalities for Windows, which enable us to build native Windows apps 5x faster. This integration enables us to create a modern GUI with Windows 10 looks and responsive controls for our Python Machine Learning applications.
Python4Delphi makes it easy to use Python as a scripting language for a python windows GUI-builder like Delphi applications. It also comes with an extensive range of demos and tutorials. With Python4Delphi, you can integrate any Python features, functionalities, and libraries with Delphi to create a nice GUI for your Machine Learning applications on Windows.
In this tutorial, we will discuss the following:
How to use these 5 Python libraries with different Machine Learning capabilities to perform Machine Learning in Windows Apps: Matplotlib, NLTK, Pillow, OpenCV, and Keras.
All of them would be integrated with Python4Delphi to create Windows Apps with Machine Learning capabilities.
Prerequisites: Before we begin to work, download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out the easy instructions found in Getting Started With Python4Delphi video by Jim McKeeth.
Time to get started!
First, open and run our Python GUI using project Demo01
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 Demo01
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.
1. How do I enable Matplotlib inside Python4Delphi in Windows?
Matplotlib is one of the most popular and oldest plotting libraries in Python which is used in Machine Learning. In Machine Learning, Matplotlib helps to gain insights from a huge amount of data through different data visualization techniques.
With the high demand for Data Science and Analytics skill sets, drawing graphics programmatically is a very popular task these days. You can easily solve these tasks by combining the Matplotlib library with Python4Delphi (P4D). Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits (in this post, Python GUI by Delphi’s VCL using P4D)!
After installing Python4Delphi properly, you can get matplotlib
using pip
or easy install to your command prompt:
and don’t forget to put the path where your Matplotlib installed, to the System Environment Variables, here are the example:
[crayon-673a2a84b7f63800071687/]The following is a code example of matplotlib
to create Stacked Horizontal Bar Chart to Visualize Discrete Distribution (run this inside the lower Memo
of Python4Delphi
Demo01
GUI):
Here is the result in Python GUI:
Matplotlib is a comprehensive Python library for creating static, animated, and interactive visualizations. Matplotlib produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms.
2. How do I use NLTK inside Python4Delphi in Windows?
NLTK is a leading platform for building Python programs to work with human language data. Natural Language Processing or NLP for short — in a wide sense, to cover any kind of computer manipulation of natural language. NLP is a field in Machine Learning with the ability of a computer to understand, analyze, manipulate, and potentially generate human language.
NLTK provides easy-to-use interfaces to over 50 corpora and lexical resources such as WordNet [5], along with a suite of text processing libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning, wrappers for industrial-strength NLP libraries, and an active discussion forum.
Do you want to perform Natural Language Processing tasks like predicting text, analyzing & visualizing sentence structure, Sentiment Analysis, gender classification, etc. in the Windows GUI app? This section will show you how to get started!
First, here is how you can get nltk
:
Practical work in Natural Language Processing typically uses large bodies of linguistic data or corpora. You can add the popular NLTK datasets to your system using this command:
[crayon-673a2a84b7f67336587255/]The following is The following is a code example of NLTK to analyze sentence structure or grammar using NLTK data from treebank
corpus
: Wall Street Journal sample number 9 (wsj_0009.mrg
). Run this inside the lower Memo
of Python4Delphi
Demo01
GUI:
Here is the result in Python GUI:
3. How do I enable Pillow inside Python4Delphi in Windows?
Pillow or PIL is the Python Imaging Library that adds image processing capabilities to your Python interpreter. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. The core image library is designed for fast access to data stored in a few basic pixel formats. It should provide a solid foundation for a general image processing tool.
Another reason you would consider using Pillow is the fact that it is quite easy to use and very popular with Python users. Pillow is a common tool in the arsenal of most Data Scientists who work with images. Pillow provides various image processing methods that are very useful especially in augmenting training data for computer vision problems.
This section will guide you to combine Python4Delphi with Pillow library, inside Delphi and C++Builder, from installing Pillow with pip
to perform simple geometrical transformations to the image.
First, here is how you can get Pillow
:
The following is a code example of Pillow
to perform geometrical transformations with the image (run this inside the lower Memo
of Python4Delphi
Demo01
GUI):
Here is the result in Python GUI:
4. How do I use OpenCV inside Python4Delphi in Windows?
OpenCV (Open Source Computer Vision Library) is an open-source Computer Vision and Machine Learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial products. OpenCV supports various programming languages including Python.
OpenCV has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art Computer Vision and Machine Learning algorithms. These algorithms can be used to detect and recognize faces, identify objects, classify human actions in videos, track camera movements, track moving objects, extract 3D models of objects, produce 3D point clouds from stereo cameras, stitch images together to produce a high-resolution image of an entire scene, find similar images from an image database, remove red eyes from images taken using flash, follow eye movements, recognize scenery and establish markers to overlay it with augmented reality, etc.
First, here is how you can get opencv
to work with Python4Delphi to create GUI with Computer Vision and Machine Learning capabilities:
The following is a code example of OpenCV to perform perspective transformation of an image (run this inside the lower Memo
of Python4Delphi
Demo01
GUI):
Let’s see the result:
5. How do I enable Keras inside Python4Delphi in Windows?
Keras is a high-level neural networks API for Python. Keras acts as an interface for the TensorFlow library. As a central part of the tightly-connected TensorFlow 2.0 ecosystem, Keras is covering every step of the Machine Learning workflow, from data management to hyperparameter training to deployment solutions.
Keras is designed for human beings, not machines. Keras follows best practices for reducing cognitive load: It offers consistent and simple APIs, minimizes the number of user actions required for common use cases, and it provides clear and actionable error messages.
It’s popularity? You don’t need to worry! Keras has extensive documentation and developer guides, and also the most used deep learning framework among top-5 winning teams on Kaggle. Keras was also the 10th most cited tool in the KDnuggets 2018 software poll and registered a 22% usage. Keras is used by CERN, NASA, NIH, and many more scientific organizations around the world (and yes, Keras is used at the LHC).
Are you looking for a simple, flexible, and powerful deep learning library, and build a nice GUI for them? You can deliver enterprise-grade AI solutions easily by combining Keras and Python4Delphi library, inside Delphi and C++Builder.
First, here is how you can get keras
:
The following is a code example of Keras to prepare and visualize famous Kaggle’s Cats vs Dogs dataset for Deep Learning (run this inside the lower Memo
of Python4Delphi
Demo01
GUI):
Let’s see the result:
Read more: https://pythongui.org/artificial-intelligence-solutions-with-keras-library-in-a-windows-python-app/
Want to know some more? Then check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.
References & further readings
[1] Microsoft Learn. (2022).
Get Started with Windows Machine Learning. learn.microsoft.com/en-us/windows/ai/windows-ml/get-started.
[2] Hakim, M. A. (2021).
Article01 – 5 Python’s Machine Learning Libraries. embarcaderoBlog-repo GitHub. github.com/MuhammadAzizulHakim/ embarcaderoBlog-repo/tree/main/Article01%20-%205%20Python’s%20Machine%20Learning %20Libraries
[3] Hakim, M. A. (2021).
Learn To Work With Real-World Graphics Using The Python Matplotlib Library In A Delphi Windows App. PythonGUI.org. Embarcadero Technologies. pythongui.org/learn-to-work-with-real-world-graphics-using-the-python-matplotlib-library-in-a-delphi-windows-app
[4] Hakim, M. A. (2021).
Quickly Build A Python GUI App With Powerful Natural Language Processing Capabilities Using NLTK Library In A Delphi Windows App. PythonGUI.org. Embarcadero Technologies. pythongui.org/quickly-build-a-python-gui-app-with-powerful-natural-language-processing-capabilities-using-nltk-library-in-a-delphi-windows-app
[5] Princeton University. (2010).
“About WordNet.”. WordNet. Princeton University. wordnet.princeton.edu
[6] Hakim, M. A. (2021).
Learn To Build A Python GUI For Easily Processing Images With Pillow Library In A Delphi Windows App. PythonGUI.org. Embarcadero Technologies. pythongui.org/learn-to-build-a-python-gui-for-easily-processing-images-with-pillow-library-in-a-delphi-windows-app
[7] Hakim, M. A. (2021).
Learn To Build A Python GUI For Computer Vision Tasks With Powerful OpenCV Library In A Delphi Windows App. PythonGUI.org. Embarcadero Technologies. pythongui.org/learn-to-build-a-python-gui-for-computer-vision-tasks-with-powerful-opencv-library-in-a-delphi-windows-app
[8] Hakim, M. A. (2021).
Artificial Intelligence Solutions With Keras Library In A Windows Python App. PythonGUI.org. Embarcadero Technologies. pythongui.org/artificial-intelligence-solutions-with-keras-library-in-a-windows-python-app