SlideShare a Scribd company logo
PyTorch for Delphi
with the
Python Data Science Libraries
June 9th, 2022
jim.mckeeth@embarcadero.com
Slides, links, replay: https://blogs.embarcadero.com/?p=145025
PyTorch for Delphi with the Python Data Sciences Libraries
The next installment of the Embarcadero Open Source Live Stream takes a look at the Delphi side of the Python
Ecosystem with the new Python Data Sciences Libraries and related projects that make it super easy write Delphi
code against Python libraries and easily deploy on Windows, Linux, MacOS, and Android. Specific examples with
the Python Natural Language Toolkit and PyTorch, the library that powers projects like Tesla Autopilot, Uber's
Pyro, Hugging Face's Transformers.
This is part of a series of regular live streams discussing the latest in Embarcadero open source projects. Hosted
by Jim McKeeth and joined by members of the community and developers involved in these open source projects,
as well as members of Embarcadero and Idera’s Product Management. A great opportunity to see behind the
scenes and help shape the future of Embarcadero’s Open Source projects.
If you are interested in machine learning, artificial intelligence, or data sciences then you want to join this webinar!
Description
Slides, replay, links, etc. blogs.embarcadero.com/?p=145025
Who’s on the Stream?
● Jim McKeeth - Embarcadero Developer Relations
● Kunarapu Priyatham - Python Developer & Tech Writer
● Lucas Moura Belo - Delphi & Python Developer
● Kiriakos Vlahos - Maintainer of PyScripter and Python4Delphi
● Chris Gardner - Whole Tomato Visual Assist Lead Developer
● Marco Cantu - RAD Studio & Delphi PM
● And others who may or may not chime in . . .
Priyatham
Jim
Lucas
Chris
Kiriakos
We Need More Components!
● We are more productive when there is an
existing component or library already
● Delphi and C++Builder has a huge rich
ecosystem of Tech Partners and open source
● But wouldn’t be great to have EVEN MORE?
● Python has one of the richest ecosystems,
especially for data sciences, AI, & ML
● What if Delphi & C++Builder could easily
USE THEM ALL?
XKCD on Python
There is a package for everything!
● xkcd.com/353/ from December 5th, 2007
● explainxkcd.com/wiki/index.php/353:_Python
[A friend is talking to Cueball, who is floating in the sky.]
Friend: You're flying! How?
Cueball: Python!
Cueball: I learned it last night! Everything is so simple!
Cueball: Hello world is just pr i nt " He l l o, W
or l d! "
Friend: I dunno... Dynamic typing? Whitespace?
Cueball: Come join us! Programming is fun again! It's a whole
new world up here!
Friend: But how are you flying?
Cueball: I just typed 'i mpor t a nt i gr a vi t y'
Friend: That's it?
Cueball: ...I also sampled everything in the medicine cabinet for
comparison.
Cueball: But I think this is the python.
In response to this comic, the Python developers implemented the
module a nt i gr a vi t y. When you import it, the default web
browser will open this comic.
General Notes and Comments
● Most all projects are open source, MIT licensed, and hosted on GitHub.
● Embarcadero is directly sponsoring the developers and development.
● While the focus is on Delphi, we expect C++Builder will work eventually.
○ Once the Delphi side is stable we will look more closely at C++Builder where it makes sense.
○ There are already resources showing how to use Python4Delphi with C++Builder.
● All of these projects are available and mostly working today.
○ They are under active development, so consider them beta or alpha releases….
● Unless otherwise stated, everything works on
○ Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux
● We are looking for feedback, pull requests, contributors, and forks on all
Embarcadero Open Source projects!
● ⭐ Starring a project is a great way to show your interest!
It’s not a Competition
● Language choice isn’t a zero sum game.
● Developers have multiple tools on their workbench.
● When tools work together then a developer can use both!
● It is about finding the right tool for each task.
● We use SQL to talk to databases, JavaScript and HTML run
the web.
● Having specialized tools for different tasks doesn’t detract
from favorite tools.
● You can always find a specific task
that another tool is better for,
but no one tool is that best
for all tasks.
Python Delphi
Tensorflow
NumPy
etc.
GitHub
GetIt
Boss
Chocolatey
PyPi
Conda
Forge
Python Developers
Delphi
Developers
Delphi Extensions
for Python
Python4Delphi
PyScripter
DelphiVCL
DelphiFMX
Lightweight
Python
Wrappers
P4D
Data Sciences
Python
Environments
PIP
FMX App Builder D4P Exporter
Python and Delphi Ecosystem
1. Free Python IDE and libraries
○ Free give away to Python developers.
2. Use designer export from Delphi
○ Dipping toe into Delphi CE or a free trial.
3. Import Python libraries into Delphi
○ Starting to explore the power of hybrid apps.
4. Build native Delphi modules for Python
○ Use Delphi’s native compiler to add speed and features to
Python.
5. Full Hybrid Delphi + Python Power
○ The ultimate stage of development, ushering in the final
technological singularity, leading to total universal domination
and the enlightenment of all humankind.
PyScripter, DelphiFMX,
DelphiVCL
Lightweight Python
Wrappers
& Data Sciences
Python4Delphi &
Delphi Extensions
for Python
Available via GetIt.
Python4Delphi: The Bridge
Python for Delphi (P4D) is a set of components that wrap up the Python Library into Delphi. They let
Delphi developers easily execute Python scripts, create new Python modules, and new Python
types. You can create Python extension modules and much more. P4D provides different levels of
functionality:
● Low-level access to the Python API
● High-level bi-directional interaction with Python
● Access to Python objects using Delphi custom
variants (VarPyth.pas)
● Wrapping of Delphi objects for use in Python
scripts using RTTI (WrapDelphi.pas)
● Creating Python extension modules with Delphi classes and functions
Supports Android (64-bit ARM), Windows (32 & 64-bit x86), MacOS (x86 & ARM), and Linux (64-bit x86)
Embarcadero’s Fork of P4D
github.com/Embarcadero/Python4Delphi
Originally maintained by Kiriakos Vlahos (aka PyScripter)
● GitHub - Where all the projects are hosted: github.com/embarcadero
● GetIt - The Embarcadero package manager. When the projects for Delphi developers are
ready for general use they can easily be installed via GetIt. getitnow.embarcadero.com
● Boss - Delphi dependency manager. Plan to use to make it easy to manage
dependencies between projects. github.com/hashload/boss
● Chocolatey - General Windows package manager. Simplify deployment and installation
of development builds.
● pip - Package Installer for Python pip.pypa.io
● PyPi - The Python Package Index is the official third-party software repository for
Python. Default source for pip. pypi.org/user/Embarcadero
● Conda - Alternative and very popular Python package manager. docs.conda.io
● Conda Forge - Community-led collection of distributions for the conda package
manager. conda-forge.org
Other Pieces in the Ecosystem GitHub
Boss
Chocolatey
PyPi
Conda
Forge
GetIt
pip
For Delphi Developers
Bringing the best of Python to Delphi developers.
Pure Object Pascal access to Python libraries.
Goals
● Give Delphi (and eventually C++Builder)
developers access to all Python libraries
● No Python knowledge or code required
● But still give full access
● Simple development setup
● Simple end user deployment
● No internet connection required
● Cross platform
This is an early access preview, but you
are invited to start using and contributing.
Three All New Projects
Powered by Python4Delphi
Python Environments
● Delphi components that simplify the deployment and configuration of Python
environments
● Freeing Delphi developers from needing to worry about Python
● Supports Python versions 3.7, 3.8, 3.9, & 3.10
● Currently 3 different options:
○ Use an existing Python environment
○ Redistribute or download a Python environment archive
○ Embed the redistributable within the program
● At runtime it automatically verifies and configures the environment, including
PIP or Conda package managers
● The framework is very modular, flexible, and customizable
● Installs necessary Python modules
● Working on Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux
Early Alpha - Should mostly work, still adding features
github.com/Embarcadero/PythonEnviroments/
For Delphi
Developers
Lightweight Python Wrappers
● Framework for creating a lightweight wrapper around a Python library
turning it into a Delphi component
● Makes adding a new Python library super quick and easy
● Manages the necessary Python modules via pip or Conda
● Allows for a simple translation of Python code into Delphi code
● Uses late binding giving it a more flexible syntax
● Letting Delphi developers use pure Delphi to access Python libraries
To Do:
● Automatic wrapper generation
● Python to Delphi code translation
● Code completion and better IDE integration
● Your suggestions!
Early Alpha - Should mostly work, still adding features
github.com/Embarcadero/Lightweight-Python-Wrappers
For Delphi
Developers
P4D Data Sciences
● Based on the Lightweight Python Wrappers, Python Environments, and
Python4Delphi
● Delphi components for popular Python Data Sciences tools
● Currently includes:
○ Tensorflow, NumPy, PyTorch Vision, PyTorch, MatPlotLib, Natural Language
Toolkit (NLTK), OpenCV, and Scikit-learn
● Even includes some samples
● Surprisingly easy to make and use
○ Literally a couple hours work to add and test a new library
● Looking at additional libraries to add….
Early Alpha - Should mostly work, still adding features
github.com/Embarcadero/P4D-Data-Sciences
Even includes some demos
For Delphi
Developers
Example of adding a library:
Natural Language Toolkit
(NLTK)
For Delphi
Developers
Natural Language
Toolkit (NLTK)
● This is the code to wrap a new
Python library for Delphi
● Looking into automatic importer
● All the details and complexity are
encapsulated in the Lightweight
Python Wrappers
● The Python Environment handles all
the requirements and installation
unit NLTK;
procedure TNLTK.Prepare( const AModel: TPyPackageModel);
begin
inherited ;
with AModel do begin
PackageName := 'nltk' ;
PackageManagers.Add(TPyPackageManagerKind. pip ,
TPyPackageManagerPip.Create( 'nltk' ));
end;
end;
● Name of Python
module
● Package manager for
installation
For Delphi
Developers
● Simple code found on nltk.org
● Showing off basic functionality
● Python code running in the REPL,
with results displayed inline
Demo Tokenize and tag some text:
>>> import nltk
>>> nltk.download( 'popular' )
>>> sentence = """At eight o'clock on Thursday morning
... Arthur didn't feel very good."""
>>> tokens = nltk . word_tokenize(sentence)
>>> tokens
['At', 'eight', "o'clock", 'on', 'Thursday', 'morning',
'Arthur', 'did', "n't", 'feel', 'very', 'good', '.']
>>> tagged = nltk . pos_tag(tokens)
>>> tagged[ 0: 6]
[('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'),
('Thursday', 'NNP'), ('morning', 'NN')]
Identify named entities:
>>> entities = nltk . chunk . ne_chunk(tagged)
>>> entities
Tree('S', [('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'),
('on', 'IN'), ('Thursday', 'NNP'), ('morning', 'NN'),
Tree('PERSON', [('Arthur', 'NNP')]),
('did', 'VBD'), ("n't", 'RB'), ('feel', 'VB'),
('very', 'RB'), ('good', 'JJ'), ('.', '.')])
Downloads the required data.
Only necessary once.
● There are a series of event handlers
notifying your program of state of the
Python Environment.
● Here is the Delphi version of the
Python code.
● The output of each step is displayed
in the list boxes.
● When compiled there is a single EXE.
● At runtime the Environment sets up a
nested Python environment with all
the necessary dependencies.
Demo with NLTK1 do begin
nltk.download( 'popular' );
var tokens :=
nltk.word_tokenize(memo1.lines.Text);
VarPyToStrings(tokens,ListBox1.Items);
var tagged :=
nltk.pos_tag(tokens);
VarPyToStrings(tagged,ListBox2.Items);
var entities :=
nltk.chunk.ne_chunk(tagged);
VarPyToStrings(entities, ListBox3.Items);
end;
For Delphi
Developers
● Add the following components:
○ TPythonEngine
○ TPyEmbeddedResEnvironment310
○ TNumPy
○ TNLTK
● Connect the components
● Make the UI
● Leave the Tokenize button disabled, then use an
event handler from the Environment to enable it
when everything is setup.
Demo
For Delphi
Developers
● One first run the Environment is setup
with all dependencies. Usually takes a
few seconds.
● On subsequent runs it takes a second to
validate the environment, load the
libraries, and start the engine.
● The program uses the event handlers to
enable the user interface based on the
state.
Demo
For Delphi
Developers
● The Python environment can be installed
anywhere (or an existing one can be used) but
the default is the EXE folder.
● It can also be created during the installation
process, before the program first runs.
● Here we see our sample program in 43 MB.
● And it extracted and created a 95 MB Python
environment.
● The same project can compile and run
identically on Android, Windows (32 & 64-bit),
MacOS (x86 & ARM), and Linux
Demo
For Delphi
Developers
Demo with Delphi
For Delphi
Developers
Demo
● PyTorch is an open source machine learning framework 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)
● Used in projects like Tesla Autopilot, Uber's Pyro, Hugging Face's Transformers,
and others
● Delphi demo is part of P4D Data Sciences
○ This is a Thumbs Up and Thumbs Down image classification system with mobile image collection
○ github.com/Embarcadero/P4D-Data-Sciences/tree/main/demos/PyTorch/
■ App - Android App Source
■ Install - Installs dependencies and sets up environment on server
■ Server - WebBroker server
■ Train - Called by server to do the training and process the data
■ Training_Data - Pre collected images
What’s Next?
It’s still early access, but
what else is possible?
What’s Next
● Still more work - in early stages of
development
● Automatic wrapper generation
● More libraries
● Python to Delphi code translation
○ Translate Python sample code
● Documentation for the full stack and for
using the imported libraries
● Code completion and better IDE integration
● Your suggestions!
Other Potential Python Libraries
● Keras - ML library that runs on both CPU and GPU
● LightGBM by Microsoft - Used for ML ranking, classification, etc.
● Aesara - Multi-dimensional arrays mathematical expressions
● BeautifulSoup - Scrapes data from web pages
● Pillow - Image manipulation
● MoviePy - Video Editing
● Seaborn - Drawing attractive statistical graphics
● YOLOv5 - Pretrained object detection architectures and models
lightgbm.readthedocs.io
aesara.readthedocs.io
keras.io
crummy.com/software/BeautifulSoup/
Python Pillow
python-pillow.org
zulko.github.io/moviepy
seaborn.pydata.org
For Delphi
Developers
● See the list of the most popular Python
packages on PyPi in the last 30 days.
● None of these are on the previous slides.
● Can every Python library be available for
Delphi developers? One way to find out….
pypistats.org/top - pypi.org
Tip of the Iceberg Rank Library Downloads
1 boto3 343,267,820
2 urllib3 214,453,654
3 botocore 211,027,562
4 requests 206,502,136
5 idna 176,641,902
6 setuptools 173,382,430
7 s3transfer 171,067,399
8 typing-extensions 165,570,269
9 six 156,492,192
10 certifi 151,478,041
11 python-dateutil 149,953,838
12 pyyaml 142,509,567
13 charset-normalizer 139,528,384
14 awscli 122,370,481
15 click 117,707,552
16 wheel 115,961,643
17 cryptography 110,978,677
18 jinja2 109,342,363
19 pyparsing 103,909,140
20 rsa 103,612,934
For Delphi
Developers
● Try the projects
● Star the projects on GitHub
● File bug reports
● Make a fork
● Issue a pull request
● Add features and fix bugs
● Tell your friends
● Write a blog post
● Make a demo
We Need Your Help!
Q & A
General Notes and Comments
● Most all projects are open source, MIT licensed, and hosted on GitHub.
● Embarcadero is directly sponsoring the developers and development.
● While the focus is on Delphi, we expect C++Builder will work eventually.
○ Once the Delphi side is stable we will look more closely at C++Builder where it makes sense.
○ There are already resources showing how to use Python4Delphi with C++Builder.
● All of these projects are available and mostly working today.
○ They are under active development, so consider them beta or alpha releases….
● Unless otherwise stated, everything works on
○ Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux
● We are looking for feedback, pull requests, contributors, and forks on all
Embarcadero Open Source projects!
● ⭐ Starring a project is a great way to show your interest!
PyTorch for Delphi
with the
Python Data Science Libraries

More Related Content

PDF
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
Embarcadero Technologies
 
PDF
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Embarcadero Technologies
 
PDF
Python for Delphi Developers - Part 2
Embarcadero Technologies
 
PPTX
Python for Delphi Developers - Part 1 Introduction
Embarcadero Technologies
 
PDF
EKON 25 Python4Delphi_mX4
Max Kleiner
 
PDF
Ekon 25 Python4Delphi_MX475
Max Kleiner
 
PDF
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
pythoncharmers
 
PPTX
Introduction to Python Programming
Akhil Kaushik
 
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
Embarcadero Technologies
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Embarcadero Technologies
 
Python for Delphi Developers - Part 2
Embarcadero Technologies
 
Python for Delphi Developers - Part 1 Introduction
Embarcadero Technologies
 
EKON 25 Python4Delphi_mX4
Max Kleiner
 
Ekon 25 Python4Delphi_MX475
Max Kleiner
 
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
pythoncharmers
 
Introduction to Python Programming
Akhil Kaushik
 

Similar to PyTorch for Delphi - Python Data Sciences Libraries.pdf (20)

PDF
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
Linaro
 
PDF
PyCon2022 - Building Python Extensions
Henry Schreiner
 
PDF
nativeappdevelopmentwithpython1658264723355.pdf
scossy1
 
PDF
PyData Boston 2013
Travis Oliphant
 
PPTX
Python and its Applications
Abhijeet Singh
 
PDF
Pythonanditsapplications 161121160425
Sapna Tyagi
 
PDF
Introduction to Python Syntax and Semantics
Adam Cook
 
PDF
Harmonic Stack for Speed
Yung-Yu Chen
 
PDF
Django Dev Environment Howto
Tzu-ping Chung
 
ZIP
An Introduction to PyPy
Michael Hudson-Doyle
 
PDF
A complete guide to Python app development.pdf
MoonTechnolabsPvtLtd
 
PDF
Notes about moving from python to c++ py contw 2020
Yung-Yu Chen
 
PPTX
2016 bioinformatics i_python_part_1_wim_vancriekinge
Prof. Wim Van Criekinge
 
PDF
A Comprehensive Overview of Python in Real-World Scenarios
NexSoftsys
 
PDF
Top 10 Python Frameworks for App Development
KateWood30
 
PDF
Samsung SDS OpeniT - The possibility of Python
Insuk (Chris) Cho
 
PDF
Python standard library & list of important libraries
grinu
 
PDF
Uber, Netflix, &YouTube are Built with Python. Here’s WHY?
Inexture Solutions
 
PDF
Build and deploy scientific Python Applications
Ramakrishna Reddy
 
PDF
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
RootedCON
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
Linaro
 
PyCon2022 - Building Python Extensions
Henry Schreiner
 
nativeappdevelopmentwithpython1658264723355.pdf
scossy1
 
PyData Boston 2013
Travis Oliphant
 
Python and its Applications
Abhijeet Singh
 
Pythonanditsapplications 161121160425
Sapna Tyagi
 
Introduction to Python Syntax and Semantics
Adam Cook
 
Harmonic Stack for Speed
Yung-Yu Chen
 
Django Dev Environment Howto
Tzu-ping Chung
 
An Introduction to PyPy
Michael Hudson-Doyle
 
A complete guide to Python app development.pdf
MoonTechnolabsPvtLtd
 
Notes about moving from python to c++ py contw 2020
Yung-Yu Chen
 
2016 bioinformatics i_python_part_1_wim_vancriekinge
Prof. Wim Van Criekinge
 
A Comprehensive Overview of Python in Real-World Scenarios
NexSoftsys
 
Top 10 Python Frameworks for App Development
KateWood30
 
Samsung SDS OpeniT - The possibility of Python
Insuk (Chris) Cho
 
Python standard library & list of important libraries
grinu
 
Uber, Netflix, &YouTube are Built with Python. Here’s WHY?
Inexture Solutions
 
Build and deploy scientific Python Applications
Ramakrishna Reddy
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
RootedCON
 
Ad

More from Embarcadero Technologies (20)

PDF
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Embarcadero Technologies
 
PDF
Linux GUI Applications on Windows Subsystem for Linux
Embarcadero Technologies
 
PDF
FMXLinux Introduction - Delphi's FireMonkey for Linux
Embarcadero Technologies
 
PDF
RAD Industrial Automation, Labs, and Instrumentation
Embarcadero Technologies
 
PDF
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embarcadero Technologies
 
PDF
Rad Server Industry Template - Connected Nurses Station - Setup Document
Embarcadero Technologies
 
PPTX
TMS Google Mapping Components
Embarcadero Technologies
 
PDF
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Embarcadero Technologies
 
PPTX
Useful C++ Features You Should be Using
Embarcadero Technologies
 
PPTX
Getting Started Building Mobile Applications for iOS and Android
Embarcadero Technologies
 
PPTX
Embarcadero RAD server Launch Webinar
Embarcadero Technologies
 
PPTX
ER/Studio 2016: Build a Business-Driven Data Architecture
Embarcadero Technologies
 
PPTX
The Secrets of SQL Server: Database Worst Practices
Embarcadero Technologies
 
PDF
Driving Business Value Through Agile Data Assets
Embarcadero Technologies
 
PDF
Troubleshooting Plan Changes with Query Store in SQL Server 2016
Embarcadero Technologies
 
PDF
Great Scott! Dealing with New Datatypes
Embarcadero Technologies
 
PDF
Agile, Automated, Aware: How to Model for Success
Embarcadero Technologies
 
PDF
What's New in DBArtisan and Rapid SQL 2016
Embarcadero Technologies
 
PDF
Is This Really a SAN Problem? Understanding the Performance of Your IO Subsy...
Embarcadero Technologies
 
PDF
RAD Studio, Delphi and C++Builder 10 Feature Matrix
Embarcadero Technologies
 
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Embarcadero Technologies
 
Linux GUI Applications on Windows Subsystem for Linux
Embarcadero Technologies
 
FMXLinux Introduction - Delphi's FireMonkey for Linux
Embarcadero Technologies
 
RAD Industrial Automation, Labs, and Instrumentation
Embarcadero Technologies
 
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embarcadero Technologies
 
Rad Server Industry Template - Connected Nurses Station - Setup Document
Embarcadero Technologies
 
TMS Google Mapping Components
Embarcadero Technologies
 
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Embarcadero Technologies
 
Useful C++ Features You Should be Using
Embarcadero Technologies
 
Getting Started Building Mobile Applications for iOS and Android
Embarcadero Technologies
 
Embarcadero RAD server Launch Webinar
Embarcadero Technologies
 
ER/Studio 2016: Build a Business-Driven Data Architecture
Embarcadero Technologies
 
The Secrets of SQL Server: Database Worst Practices
Embarcadero Technologies
 
Driving Business Value Through Agile Data Assets
Embarcadero Technologies
 
Troubleshooting Plan Changes with Query Store in SQL Server 2016
Embarcadero Technologies
 
Great Scott! Dealing with New Datatypes
Embarcadero Technologies
 
Agile, Automated, Aware: How to Model for Success
Embarcadero Technologies
 
What's New in DBArtisan and Rapid SQL 2016
Embarcadero Technologies
 
Is This Really a SAN Problem? Understanding the Performance of Your IO Subsy...
Embarcadero Technologies
 
RAD Studio, Delphi and C++Builder 10 Feature Matrix
Embarcadero Technologies
 
Ad

Recently uploaded (20)

PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
Exploring AI Agents in Process Industries
amoreira6
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
oapresentation.pptx
mehatdhavalrajubhai
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
Presentation about variables and constant.pptx
safalsingh810
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 

PyTorch for Delphi - Python Data Sciences Libraries.pdf

  • 1. PyTorch for Delphi with the Python Data Science Libraries June 9th, 2022 [email protected] Slides, links, replay: https://blogs.embarcadero.com/?p=145025
  • 2. PyTorch for Delphi with the Python Data Sciences Libraries The next installment of the Embarcadero Open Source Live Stream takes a look at the Delphi side of the Python Ecosystem with the new Python Data Sciences Libraries and related projects that make it super easy write Delphi code against Python libraries and easily deploy on Windows, Linux, MacOS, and Android. Specific examples with the Python Natural Language Toolkit and PyTorch, the library that powers projects like Tesla Autopilot, Uber's Pyro, Hugging Face's Transformers. This is part of a series of regular live streams discussing the latest in Embarcadero open source projects. Hosted by Jim McKeeth and joined by members of the community and developers involved in these open source projects, as well as members of Embarcadero and Idera’s Product Management. A great opportunity to see behind the scenes and help shape the future of Embarcadero’s Open Source projects. If you are interested in machine learning, artificial intelligence, or data sciences then you want to join this webinar! Description Slides, replay, links, etc. blogs.embarcadero.com/?p=145025
  • 3. Who’s on the Stream? ● Jim McKeeth - Embarcadero Developer Relations ● Kunarapu Priyatham - Python Developer & Tech Writer ● Lucas Moura Belo - Delphi & Python Developer ● Kiriakos Vlahos - Maintainer of PyScripter and Python4Delphi ● Chris Gardner - Whole Tomato Visual Assist Lead Developer ● Marco Cantu - RAD Studio & Delphi PM ● And others who may or may not chime in . . . Priyatham Jim Lucas Chris Kiriakos
  • 4. We Need More Components! ● We are more productive when there is an existing component or library already ● Delphi and C++Builder has a huge rich ecosystem of Tech Partners and open source ● But wouldn’t be great to have EVEN MORE? ● Python has one of the richest ecosystems, especially for data sciences, AI, & ML ● What if Delphi & C++Builder could easily USE THEM ALL?
  • 5. XKCD on Python There is a package for everything! ● xkcd.com/353/ from December 5th, 2007 ● explainxkcd.com/wiki/index.php/353:_Python [A friend is talking to Cueball, who is floating in the sky.] Friend: You're flying! How? Cueball: Python! Cueball: I learned it last night! Everything is so simple! Cueball: Hello world is just pr i nt " He l l o, W or l d! " Friend: I dunno... Dynamic typing? Whitespace? Cueball: Come join us! Programming is fun again! It's a whole new world up here! Friend: But how are you flying? Cueball: I just typed 'i mpor t a nt i gr a vi t y' Friend: That's it? Cueball: ...I also sampled everything in the medicine cabinet for comparison. Cueball: But I think this is the python. In response to this comic, the Python developers implemented the module a nt i gr a vi t y. When you import it, the default web browser will open this comic.
  • 6. General Notes and Comments ● Most all projects are open source, MIT licensed, and hosted on GitHub. ● Embarcadero is directly sponsoring the developers and development. ● While the focus is on Delphi, we expect C++Builder will work eventually. ○ Once the Delphi side is stable we will look more closely at C++Builder where it makes sense. ○ There are already resources showing how to use Python4Delphi with C++Builder. ● All of these projects are available and mostly working today. ○ They are under active development, so consider them beta or alpha releases…. ● Unless otherwise stated, everything works on ○ Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux ● We are looking for feedback, pull requests, contributors, and forks on all Embarcadero Open Source projects! ● ⭐ Starring a project is a great way to show your interest!
  • 7. It’s not a Competition ● Language choice isn’t a zero sum game. ● Developers have multiple tools on their workbench. ● When tools work together then a developer can use both! ● It is about finding the right tool for each task. ● We use SQL to talk to databases, JavaScript and HTML run the web. ● Having specialized tools for different tasks doesn’t detract from favorite tools. ● You can always find a specific task that another tool is better for, but no one tool is that best for all tasks.
  • 8. Python Delphi Tensorflow NumPy etc. GitHub GetIt Boss Chocolatey PyPi Conda Forge Python Developers Delphi Developers Delphi Extensions for Python Python4Delphi PyScripter DelphiVCL DelphiFMX Lightweight Python Wrappers P4D Data Sciences Python Environments PIP FMX App Builder D4P Exporter
  • 9. Python and Delphi Ecosystem 1. Free Python IDE and libraries ○ Free give away to Python developers. 2. Use designer export from Delphi ○ Dipping toe into Delphi CE or a free trial. 3. Import Python libraries into Delphi ○ Starting to explore the power of hybrid apps. 4. Build native Delphi modules for Python ○ Use Delphi’s native compiler to add speed and features to Python. 5. Full Hybrid Delphi + Python Power ○ The ultimate stage of development, ushering in the final technological singularity, leading to total universal domination and the enlightenment of all humankind. PyScripter, DelphiFMX, DelphiVCL Lightweight Python Wrappers & Data Sciences Python4Delphi & Delphi Extensions for Python Available via GetIt.
  • 10. Python4Delphi: The Bridge Python for Delphi (P4D) is a set of components that wrap up the Python Library into Delphi. They let Delphi developers easily execute Python scripts, create new Python modules, and new Python types. You can create Python extension modules and much more. P4D provides different levels of functionality: ● Low-level access to the Python API ● High-level bi-directional interaction with Python ● Access to Python objects using Delphi custom variants (VarPyth.pas) ● Wrapping of Delphi objects for use in Python scripts using RTTI (WrapDelphi.pas) ● Creating Python extension modules with Delphi classes and functions Supports Android (64-bit ARM), Windows (32 & 64-bit x86), MacOS (x86 & ARM), and Linux (64-bit x86) Embarcadero’s Fork of P4D github.com/Embarcadero/Python4Delphi Originally maintained by Kiriakos Vlahos (aka PyScripter)
  • 11. ● GitHub - Where all the projects are hosted: github.com/embarcadero ● GetIt - The Embarcadero package manager. When the projects for Delphi developers are ready for general use they can easily be installed via GetIt. getitnow.embarcadero.com ● Boss - Delphi dependency manager. Plan to use to make it easy to manage dependencies between projects. github.com/hashload/boss ● Chocolatey - General Windows package manager. Simplify deployment and installation of development builds. ● pip - Package Installer for Python pip.pypa.io ● PyPi - The Python Package Index is the official third-party software repository for Python. Default source for pip. pypi.org/user/Embarcadero ● Conda - Alternative and very popular Python package manager. docs.conda.io ● Conda Forge - Community-led collection of distributions for the conda package manager. conda-forge.org Other Pieces in the Ecosystem GitHub Boss Chocolatey PyPi Conda Forge GetIt pip
  • 12. For Delphi Developers Bringing the best of Python to Delphi developers. Pure Object Pascal access to Python libraries.
  • 13. Goals ● Give Delphi (and eventually C++Builder) developers access to all Python libraries ● No Python knowledge or code required ● But still give full access ● Simple development setup ● Simple end user deployment ● No internet connection required ● Cross platform This is an early access preview, but you are invited to start using and contributing.
  • 14. Three All New Projects Powered by Python4Delphi
  • 15. Python Environments ● Delphi components that simplify the deployment and configuration of Python environments ● Freeing Delphi developers from needing to worry about Python ● Supports Python versions 3.7, 3.8, 3.9, & 3.10 ● Currently 3 different options: ○ Use an existing Python environment ○ Redistribute or download a Python environment archive ○ Embed the redistributable within the program ● At runtime it automatically verifies and configures the environment, including PIP or Conda package managers ● The framework is very modular, flexible, and customizable ● Installs necessary Python modules ● Working on Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux Early Alpha - Should mostly work, still adding features github.com/Embarcadero/PythonEnviroments/ For Delphi Developers
  • 16. Lightweight Python Wrappers ● Framework for creating a lightweight wrapper around a Python library turning it into a Delphi component ● Makes adding a new Python library super quick and easy ● Manages the necessary Python modules via pip or Conda ● Allows for a simple translation of Python code into Delphi code ● Uses late binding giving it a more flexible syntax ● Letting Delphi developers use pure Delphi to access Python libraries To Do: ● Automatic wrapper generation ● Python to Delphi code translation ● Code completion and better IDE integration ● Your suggestions! Early Alpha - Should mostly work, still adding features github.com/Embarcadero/Lightweight-Python-Wrappers For Delphi Developers
  • 17. P4D Data Sciences ● Based on the Lightweight Python Wrappers, Python Environments, and Python4Delphi ● Delphi components for popular Python Data Sciences tools ● Currently includes: ○ Tensorflow, NumPy, PyTorch Vision, PyTorch, MatPlotLib, Natural Language Toolkit (NLTK), OpenCV, and Scikit-learn ● Even includes some samples ● Surprisingly easy to make and use ○ Literally a couple hours work to add and test a new library ● Looking at additional libraries to add…. Early Alpha - Should mostly work, still adding features github.com/Embarcadero/P4D-Data-Sciences Even includes some demos For Delphi Developers
  • 18. Example of adding a library: Natural Language Toolkit (NLTK) For Delphi Developers
  • 19. Natural Language Toolkit (NLTK) ● This is the code to wrap a new Python library for Delphi ● Looking into automatic importer ● All the details and complexity are encapsulated in the Lightweight Python Wrappers ● The Python Environment handles all the requirements and installation unit NLTK; procedure TNLTK.Prepare( const AModel: TPyPackageModel); begin inherited ; with AModel do begin PackageName := 'nltk' ; PackageManagers.Add(TPyPackageManagerKind. pip , TPyPackageManagerPip.Create( 'nltk' )); end; end; ● Name of Python module ● Package manager for installation For Delphi Developers
  • 20. ● Simple code found on nltk.org ● Showing off basic functionality ● Python code running in the REPL, with results displayed inline Demo Tokenize and tag some text: >>> import nltk >>> nltk.download( 'popular' ) >>> sentence = """At eight o'clock on Thursday morning ... Arthur didn't feel very good.""" >>> tokens = nltk . word_tokenize(sentence) >>> tokens ['At', 'eight', "o'clock", 'on', 'Thursday', 'morning', 'Arthur', 'did', "n't", 'feel', 'very', 'good', '.'] >>> tagged = nltk . pos_tag(tokens) >>> tagged[ 0: 6] [('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'), ('Thursday', 'NNP'), ('morning', 'NN')] Identify named entities: >>> entities = nltk . chunk . ne_chunk(tagged) >>> entities Tree('S', [('At', 'IN'), ('eight', 'CD'), ("o'clock", 'JJ'), ('on', 'IN'), ('Thursday', 'NNP'), ('morning', 'NN'), Tree('PERSON', [('Arthur', 'NNP')]), ('did', 'VBD'), ("n't", 'RB'), ('feel', 'VB'), ('very', 'RB'), ('good', 'JJ'), ('.', '.')]) Downloads the required data. Only necessary once.
  • 21. ● There are a series of event handlers notifying your program of state of the Python Environment. ● Here is the Delphi version of the Python code. ● The output of each step is displayed in the list boxes. ● When compiled there is a single EXE. ● At runtime the Environment sets up a nested Python environment with all the necessary dependencies. Demo with NLTK1 do begin nltk.download( 'popular' ); var tokens := nltk.word_tokenize(memo1.lines.Text); VarPyToStrings(tokens,ListBox1.Items); var tagged := nltk.pos_tag(tokens); VarPyToStrings(tagged,ListBox2.Items); var entities := nltk.chunk.ne_chunk(tagged); VarPyToStrings(entities, ListBox3.Items); end; For Delphi Developers
  • 22. ● Add the following components: ○ TPythonEngine ○ TPyEmbeddedResEnvironment310 ○ TNumPy ○ TNLTK ● Connect the components ● Make the UI ● Leave the Tokenize button disabled, then use an event handler from the Environment to enable it when everything is setup. Demo For Delphi Developers
  • 23. ● One first run the Environment is setup with all dependencies. Usually takes a few seconds. ● On subsequent runs it takes a second to validate the environment, load the libraries, and start the engine. ● The program uses the event handlers to enable the user interface based on the state. Demo For Delphi Developers
  • 24. ● The Python environment can be installed anywhere (or an existing one can be used) but the default is the EXE folder. ● It can also be created during the installation process, before the program first runs. ● Here we see our sample program in 43 MB. ● And it extracted and created a 95 MB Python environment. ● The same project can compile and run identically on Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux Demo For Delphi Developers
  • 25. Demo with Delphi For Delphi Developers
  • 26. Demo ● PyTorch is an open source machine learning framework 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) ● Used in projects like Tesla Autopilot, Uber's Pyro, Hugging Face's Transformers, and others ● Delphi demo is part of P4D Data Sciences ○ This is a Thumbs Up and Thumbs Down image classification system with mobile image collection ○ github.com/Embarcadero/P4D-Data-Sciences/tree/main/demos/PyTorch/ ■ App - Android App Source ■ Install - Installs dependencies and sets up environment on server ■ Server - WebBroker server ■ Train - Called by server to do the training and process the data ■ Training_Data - Pre collected images
  • 27. What’s Next? It’s still early access, but what else is possible?
  • 28. What’s Next ● Still more work - in early stages of development ● Automatic wrapper generation ● More libraries ● Python to Delphi code translation ○ Translate Python sample code ● Documentation for the full stack and for using the imported libraries ● Code completion and better IDE integration ● Your suggestions!
  • 29. Other Potential Python Libraries ● Keras - ML library that runs on both CPU and GPU ● LightGBM by Microsoft - Used for ML ranking, classification, etc. ● Aesara - Multi-dimensional arrays mathematical expressions ● BeautifulSoup - Scrapes data from web pages ● Pillow - Image manipulation ● MoviePy - Video Editing ● Seaborn - Drawing attractive statistical graphics ● YOLOv5 - Pretrained object detection architectures and models lightgbm.readthedocs.io aesara.readthedocs.io keras.io crummy.com/software/BeautifulSoup/ Python Pillow python-pillow.org zulko.github.io/moviepy seaborn.pydata.org For Delphi Developers
  • 30. ● See the list of the most popular Python packages on PyPi in the last 30 days. ● None of these are on the previous slides. ● Can every Python library be available for Delphi developers? One way to find out…. pypistats.org/top - pypi.org Tip of the Iceberg Rank Library Downloads 1 boto3 343,267,820 2 urllib3 214,453,654 3 botocore 211,027,562 4 requests 206,502,136 5 idna 176,641,902 6 setuptools 173,382,430 7 s3transfer 171,067,399 8 typing-extensions 165,570,269 9 six 156,492,192 10 certifi 151,478,041 11 python-dateutil 149,953,838 12 pyyaml 142,509,567 13 charset-normalizer 139,528,384 14 awscli 122,370,481 15 click 117,707,552 16 wheel 115,961,643 17 cryptography 110,978,677 18 jinja2 109,342,363 19 pyparsing 103,909,140 20 rsa 103,612,934 For Delphi Developers
  • 31. ● Try the projects ● Star the projects on GitHub ● File bug reports ● Make a fork ● Issue a pull request ● Add features and fix bugs ● Tell your friends ● Write a blog post ● Make a demo We Need Your Help!
  • 32. Q & A
  • 33. General Notes and Comments ● Most all projects are open source, MIT licensed, and hosted on GitHub. ● Embarcadero is directly sponsoring the developers and development. ● While the focus is on Delphi, we expect C++Builder will work eventually. ○ Once the Delphi side is stable we will look more closely at C++Builder where it makes sense. ○ There are already resources showing how to use Python4Delphi with C++Builder. ● All of these projects are available and mostly working today. ○ They are under active development, so consider them beta or alpha releases…. ● Unless otherwise stated, everything works on ○ Android, Windows (32 & 64-bit), MacOS (x86 & ARM), and Linux ● We are looking for feedback, pull requests, contributors, and forks on all Embarcadero Open Source projects! ● ⭐ Starring a project is a great way to show your interest!
  • 34. PyTorch for Delphi with the Python Data Science Libraries