NSFW Content detector using Firebase MlKit (AutoML) . This module developed using Firebase on device AutoML and Firebase Vision.
This module contains pre trained
TensorFlow Lite(tflite) model that
compatible with AutoML. And this is an OnDeviceAutoMLImageLabeler
.
- Add the JitPack repository to your build file
Add it in your project build.gradle at the end of repositories:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:<latest_version>'
}
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add nsfw-detector and rest of the firebase dependencies
Add it in your app build.gradle
...
android {
...
aaptOptions {
noCompress "tflite"
}
}
dependencies {
...
api "com.google.firebase:firebase-ml-vision:<latest_version>"
implementation "com.google.firebase:firebase-ml-vision-automl:<latest_version>"
implementation "com.google.firebase:firebase-ml-model-interpreter:<latest_version>"
implementation 'com.github.nipunru:nsfw-detector-android:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
- Run the gradle sync
Note: Since this is on device image method, It will take some time to download the tflite model.
- Enable Firebase Please follow
this documentation
Make sure to add
google-service.json
file to your project.
- Initialize Firebase
Add this before call theNSFWDetector
FirebaseApp.initializeApp(context)
- Scan for NSFW
val bitmap: Bitmap //Image that you want to scan
val confidenceThreshold: Float //(Optional) Default is 0.7
NSFWDetector.isNSFW(bitmap,confidenceThreshold) { isNSFW, confidence, image ->
if (isNSFW){
Toast.makeText(this, "NSFW with confidence: $confidence", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "SFW with confidence: $confidence", Toast.LENGTH_SHORT).show()
}
}
Copyright (c) 2020 Nipun Ruwanpathirana
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.