Skip to content

Commit

Permalink
Add confidence level
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunru committed Mar 29, 2020
1 parent 53b1ee0 commit e49cee0
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ object NSFWDetector {
* This function return weather the bitmap is NSFW or not
* @param bitmap: Bitmap Image
* @param confidenceThreshold: Float 0 to 1 (Default is 0.7)
* @return callback with Boolean and Bitmap
* @return callback with isNSFW(Boolean), confidence(Float), and image(Bitmap)
*/
fun isNSFW(
bitmap: Bitmap,
confidenceThreshold: Float = CONFIDENCE_THRESHOLD,
callback: (Boolean, Bitmap) -> Unit
callback: (Boolean, Float, Bitmap) -> Unit
) {
var threshold = confidenceThreshold

Expand All @@ -45,29 +45,29 @@ object NSFWDetector {
when (label.text) {
LABEL_SFW -> {
if (label.confidence > threshold) {
callback(true, bitmap)
callback(true,label.confidence, bitmap)
} else {
callback(false, bitmap)
callback(false,label.confidence, bitmap)
}
}
LABEL_NSFW -> {
if (label.confidence < (1 - threshold)) {
callback(true, bitmap)
callback(true,label.confidence, bitmap)
} else {
callback(false, bitmap)
callback(false,label.confidence, bitmap)
}
}
else -> {
callback(false, bitmap)
callback(false,0.0F , bitmap)
}
}
} catch (e: Exception) {
Log.e(TAG, e.localizedMessage ?: "NSFW Scan Error")
callback(false, bitmap)
callback(false,0.0F , bitmap)
}
}.addOnFailureListener { e ->
Log.e(TAG, e.localizedMessage ?: "NSFW Scan Error")
callback(false, bitmap)
callback(false,0.0F , bitmap)
}
}
}

0 comments on commit e49cee0

Please sign in to comment.