How We Developed an Image Recognition App in iOS 11 That Detects Inappropriate Images To Warn User About Adult Content

How We Developed an Image Recognition App in iOS 11 That Detects Inappropriate Images To Warn User About Adult Content

3.7 (73.33%) 3 votes

During WWDC 2017, Apple launched a lot of APIs and exciting frameworks for iOS11 App Development. And among all the new frameworks, Core ML is undoubtedly the most popular framework.

What’s Core ML?

As you probably know that Artificial intelligence and Machine Learning are the most trending subjects right now, the Core ML framework is used to integrate machine learning models into iOS mobile apps.

Core ML lets you integrate a wide variety of machine learning model types into your iOS app. Furthermore, in addition to supporting deep learning with over 30 layer types, it also supports standard models such as SVMs, tree ensembles, and generalized linear models.

And because it’s built on top of low level technologies such as Accelerate and Metal, the Core ML seamlessly takes the advantage of the CPU and GPU to provide maximum performance as well as efficiency.

In a nutshell, Core ML is a brand new machine learning framework, announced during this year’s WWDC event, that comes along with iOS 11. With this framework, you can integrate machine learning models into your app.

App Overview

The app we developed is fairly simple. Our image recognition application lets the user upload a picture, then the image recognition algorithm will predict whether the picture is explicit or not through image recognition API. In other words, it warns users if the picture contains any adult content.

Now, the best option for this is to add more features and create a sext spying app which can be useful for today’s parents. It’s a modern craze that scares the most parents about their children exchanging inappropriate pictures and selfies with friends or even strangers online.

But, with this app, it’s possible to add certain features which would notify a parent if the children are taking part in such activities.

How We Build Our Image Recognition App?

As you probably know that before iOS 11 release, it was not possible to integrate machine learning scripts directly into iOS apps. If we take this image recognition app example, it requires to first upload the images on a server and pass it to imagga, an image recognition technology, in order to identify whether the image contains any adult content or not.

But, in iOS11 app development, it is possible to achieve the same without leveraging any third-party API. All you have to do is get a readymade python script, convert it into Core ML data model, and integrate it into your iOS 11 app.

In the above function of “DetectScene”, we will recognise image using Core ML.

Now, before diving into the coding part, let us first describe our .mlmodel file.

We converted this file from caffe model with which we can detect inappropriate images. This model accepts images as input and provides prediction score between 0 and 1.

If the prediction score is higher than 0.8, then the image will be considered as nude. Moreover, this .mlmodel will accept image in 224×224 size, so first we had to resize our user-selected images to 224×224 with following code.