Start a Project

Implementation of Python in swift using TensorFlow

Python is an interpreted, high-level and general-purpose programming language. Python was created in the late 1980s, and first released in 1991, by Guido van Rossum as a successor to the ABC programming language. Mainly Python used for machine learning in data science.

Apple doesn’t support Python directly. TensorFlow provides a next-generation platform for machine learning. TensorFlow provides the framework to Implement interpreted python in ios both Swift & Objective-C. Please visit the TensorFlow website to know more about this framework.

In this blog, I will show you how can match 2 faces using python. To implement this we need a .tflite file where we have already implement python code and compressed it. I will share my blog to create .tflite from TensorFlow. 

Let’s Start

Swift version: 5.2
iOS version: 14
Xcode: 12.0

First Create a project from Xcode.

File ▸ New ▸ Project…. Choose the iOS ▸ Application ▸ Single View App template and create a new project.

Second, add TensorFlowLiteSwift to your project.

Add MobileFace.tflite in your project. This file I will share below.

Now create a class with the name MobileFace.

import TensorFlowLite in this class.

Now add some variable which is used in our class.

Now initialize the Interpreter object.

Add compare method inside our class. Here we will compare 2 images and return compare result.

Now Implement scaleImage method in the class.

Now Normalize and evaluate our result.

This code is enough to compare to face. Now call this compare method.

Output:

 

 

Conclusion:
We can easily implement Python using swift and it quite easy.

Next blog I will image face detection, crop, and compare using python in swift.

I hope this code will help you better to understand the implementation of Python using swift. If you feel any doubt or query please comment below.

Thank you.

 

Exit mobile version