Read More
Read now

Implementation of Python in swift using TensorFlow

Save

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:

Compare

 

 

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.

 

. . .

Leave a Comment

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


Be the first to comment.

css.php

Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

Deniel Kerr

Owner and Founder. Opencart

Talk to Sales
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home