This article was initially published on my Medium Page.
If you prefer watching a video instead of reading, here you have:
My Brief Journey on TikTok
Weeks ago, I finally decided to download TikTok. I download the app and create a new account. The first thing I always do just after registering on a social network is upload a profile picture. Strangely, TikTok did not let me do it. I tried two more times the same day, but I had no success. After that, I also tried to add friends and change my username, but still no success. I waited for a couple of days, I reopened the app, and I got this message:
I have been permanently banned from TikTok, and I don’t know why! Then I started to think. What did I do wrong? I did not post any publications or messages. I used a valid email to register, entered my real name, and tried to upload a real picture of me. I don’t believe my email and my name are a problem. What about my profile picture? Did TikTok detect it as inappropriate? Is it because I have no hair? 👨🏻🦲 How to find it out?
The System I built
Then I remembered that Amazon has a service for unsafe content detection: Rekognition; let’s try it! Additionally, you may remember this previous article of mine where I created a chat in Unity showing images from Dall-E. I will reuse the interface for this article.
This is how it works:
- The Unity client login thanks to Cognito User Pool.
- The client uploads then a picture to S3.
- Finally, the client calls a Lambda function that works directly with Rekognition to define if the picture contains unsafe content.
Amazon Services
➡️ About Cognito, I created an authenticated access using a User Pool coupled with an Identity Pool. A policy attached to the authenticated role of the Identity Pool allows users to access S3 (PutObject
) and Lambda (InvokeFunction
). If you want to know in detail how to do it, please check this previous article of mine:
➡️ The S3 Bucket is private, so nobody but the authenticated users can access it. I called it censorimagesbucket
.
➡️ I wrote the Lambda function in Python:
Notes:
- I used boto3, the AWS SDK for Python, to connect with Rekognition.
- I used all the Rekognition’s top-level category moderation labels. My face may be offensive in many ways; we never know.
- I used Rekognition’s DetectModeration API thanks to the detect_moderation_labels function and the
S3Object
parameter. - I used the very cool Pythonic any function.
Don’t forget to attach to the function’s role a policy allowing access to Rekognition and S3:
Unity
The connection between Unity3D and Amazon services is done through the AWS SDK for .NET, as described in my previous article. However, the function invocation is different this time because we have to send the filename to Lambda. We do it thanks to the Payload parameter.
Result
I performed three tests: one with a picture of Bibi, my daughter’s favorite teddy bear, a picture of a girl wearing a bikini, and a picture of myself.
It’s working great! The only unsafe content (the girl in a bikini) has been filtered successfully, and the following moderation labels have been detected:
The result is very accurate, with high confidence rates.
Conclusion
Apparently, my face is not unsafe content! I still don’t know why I have been permanently banned from TikTok, but thanks to this misadventure, I had the opportunity to discover Amazon Rekognition and realize an implementation with Unity3D.
All ids and tokens shown in this article are fake or expired; if you try to use them, you will not be able to establish any connections.
Every code of this article has been tested using Unity 2021.3.3 and Visual Studio Community 2022 for Mac. The mobile device I used to run the Unity app is a Galaxy Tab A7 Lite with Android 11.
Resources
Here are all the resources mentioned in the article:
- The Lambda function in Python
- The Lambda policy attached to the Lambda role
- The Cognito policy attached to the Cognito role
- The Unity package of the application