ha-yi/huggingface_model_to_tflite

Use case of Google AI Edge to create TFLite model for Mobile apps use.

Python

2

2 commits

updated Feb 20, 2025

See the code

README

Multi-Model NSFW Image Scanner

This project provides a comprehensive NSFW (Not Safe For Work) image detection system using multiple AI models and CLIP analysis. It includes tools for converting various NSFW detection models to TFLite format and a scanner utility to analyze directories of images.

Features

  • Multiple NSFW detection models:
    • Marqo NSFW Detection (384x384)
    • Falconsai NSFW Detection (224x224)
    • Giacomoarienti NSFW Classifier (224x224)
    • DamarJati NSFW Detection (224x224)
  • CLIP-based image content analysis
  • HTML report generation with image previews
  • Interactive results viewer with full-size image modal
  • Multi-model comparison support

Setup

  1. Create and activate a virtual environment:
$ python -m venv venv

Activate on Linux/Mac

$ source venv/bin/activate

Activate on Windows

$ .\venv\Scripts\activate
  1. Install dependencies: $ pip install -r requirements.txt

Converting Models

Before scanning images, you'll need to convert the models to TFLite format. Run the following conversion scripts:

  1. Convert Marqo NSFW Detection model:
$ python convert_nsfw_model.py
  1. Convert Falconsai NSFW Detection model:
$ python convert_falconsai_model.py
  1. Convert Giacomoarienti NSFW Classifier:
$ python convert_giacomo_model.py

Each script will download the respective model from HuggingFace and convert it to TFLite format. The converted models will be saved in the current directory.

Usage

Basic Scanning

To scan a directory of images using all available models:

$ python scan_directory.py path/to/image/directory

Using a Specific Model

To use only one model for scanning:

$ python scan_directory.py path/to/image/directory --model-type marqo

Available model types:

  • marqo
  • falconsai
  • giaco
  • damarscan

Custom Output Location

To specify a custom output report location:

$ python scan_directory.py path/to/image/directory --output custom_report.html

Output

The script generates an HTML report in the scanned directory containing:

  • Thumbnail previews of all images
  • Detection scores from each model
  • CLIP analysis results
  • Processing duration for each image
  • Interactive full-size image viewer
  • Color coding for NSFW detections

Notes

  • The scanner supports common image formats: .jpg, .jpeg, .png, .bmp, .gif
  • CLIP analysis provides additional content understanding through text-image similarity
  • First run will download the CLIP model (cached for subsequent runs)
  • Processing time varies based on image count and enabled models

Requirements

  • Python 3.7+
  • CUDA-capable GPU recommended but not required
  • Sufficient disk space for models (~1GB total)

ha-yi/huggingface_model_to_tflite

Use case of Google AI Edge to create TFLite model for Mobile apps use.

Python

2

2 commits

updated Feb 20, 2025

See the code

README

Multi-Model NSFW Image Scanner

This project provides a comprehensive NSFW (Not Safe For Work) image detection system using multiple AI models and CLIP analysis. It includes tools for converting various NSFW detection models to TFLite format and a scanner utility to analyze directories of images.

Features

  • Multiple NSFW detection models:
    • Marqo NSFW Detection (384x384)
    • Falconsai NSFW Detection (224x224)
    • Giacomoarienti NSFW Classifier (224x224)
    • DamarJati NSFW Detection (224x224)
  • CLIP-based image content analysis
  • HTML report generation with image previews
  • Interactive results viewer with full-size image modal
  • Multi-model comparison support

Setup

  1. Create and activate a virtual environment:
$ python -m venv venv

Activate on Linux/Mac

$ source venv/bin/activate

Activate on Windows

$ .\venv\Scripts\activate
  1. Install dependencies: $ pip install -r requirements.txt

Converting Models

Before scanning images, you'll need to convert the models to TFLite format. Run the following conversion scripts:

  1. Convert Marqo NSFW Detection model:
$ python convert_nsfw_model.py
  1. Convert Falconsai NSFW Detection model:
$ python convert_falconsai_model.py
  1. Convert Giacomoarienti NSFW Classifier:
$ python convert_giacomo_model.py

Each script will download the respective model from HuggingFace and convert it to TFLite format. The converted models will be saved in the current directory.

Usage

Basic Scanning

To scan a directory of images using all available models:

$ python scan_directory.py path/to/image/directory

Using a Specific Model

To use only one model for scanning:

$ python scan_directory.py path/to/image/directory --model-type marqo

Available model types:

  • marqo
  • falconsai
  • giaco
  • damarscan

Custom Output Location

To specify a custom output report location:

$ python scan_directory.py path/to/image/directory --output custom_report.html

Output

The script generates an HTML report in the scanned directory containing:

  • Thumbnail previews of all images
  • Detection scores from each model
  • CLIP analysis results
  • Processing duration for each image
  • Interactive full-size image viewer
  • Color coding for NSFW detections

Notes

  • The scanner supports common image formats: .jpg, .jpeg, .png, .bmp, .gif
  • CLIP analysis provides additional content understanding through text-image similarity
  • First run will download the CLIP model (cached for subsequent runs)
  • Processing time varies based on image count and enabled models

Requirements

  • Python 3.7+
  • CUDA-capable GPU recommended but not required
  • Sufficient disk space for models (~1GB total)