{"id":13468063,"url":"https://github.com/GantMan/nsfw_model","last_synced_at":"2025-03-26T03:31:28.884Z","repository":{"id":37271123,"uuid":"166622408","full_name":"GantMan/nsfw_model","owner":"GantMan","description":"Keras model of NSFW detector","archived":false,"fork":false,"pushed_at":"2024-02-26T07:28:05.000Z","size":495,"stargazers_count":1777,"open_issues_count":55,"forks_count":275,"subscribers_count":36,"default_branch":"master","last_synced_at":"2024-10-29T15:17:26.609Z","etag":null,"topics":["inception-v3","inceptionv3","keras","machine-learning","machinelearning","nsfw-data"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GantMan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-20T04:18:53.000Z","updated_at":"2024-10-29T09:05:53.000Z","dependencies_parsed_at":"2024-05-31T12:06:50.797Z","dependency_job_id":"42532ea4-03ad-4926-bcbc-3ad1299f11a3","html_url":"https://github.com/GantMan/nsfw_model","commit_stats":{"total_commits":99,"total_committers":14,"mean_commits":7.071428571428571,"dds":0.4242424242424242,"last_synced_commit":"699b6796a55604341fbfdffe2b27ced1d868c591"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GantMan%2Fnsfw_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GantMan%2Fnsfw_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GantMan%2Fnsfw_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GantMan%2Fnsfw_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GantMan","download_url":"https://codeload.github.com/GantMan/nsfw_model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245584897,"owners_count":20639640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inception-v3","inceptionv3","keras","machine-learning","machinelearning","nsfw-data"],"created_at":"2024-07-31T15:01:04.972Z","updated_at":"2025-03-26T03:31:28.401Z","avatar_url":"https://github.com/GantMan.png","language":"Python","readme":"![NSFW Detector logo](https://github.com/GantMan/nsfw_model/blob/master/_art/nsfw_detection.png?raw=true)\n\n# NSFW Detection Machine Learning Model\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)\n\nTrained on 60+ Gigs of data to identify:\n- `drawings` - safe for work drawings (including anime)\n- `hentai` - hentai and pornographic drawings\n- `neutral` - safe for work neutral images\n- `porn` - pornographic images, sexual acts\n- `sexy` - sexually explicit images, not pornography\n\nThis model powers [NSFW JS](https://github.com/infinitered/nsfwjs) - [More Info](https://shift.infinite.red/avoid-nightmares-nsfw-js-ab7b176978b1)\n\n## Current Status:\n\n93% Accuracy with the following confusion matrix, based on Inception V3.\n![nsfw confusion matrix](_art/nsfw_confusion93.png)\n\n## Requirements:\n\nSee [requirements.txt](requirements.txt).\n\n## Usage\n\nFor programmatic use of the library. \n\n```python\nfrom nsfw_detector import predict\nmodel = predict.load_model('./nsfw_mobilenet2.224x224.h5')\n\n# Predict single image\npredict.classify(model, '2.jpg')\n# {'2.jpg': {'sexy': 4.3454722e-05, 'neutral': 0.00026579265, 'porn': 0.0007733492, 'hentai': 0.14751932, 'drawings': 0.85139805}}\n\n# Predict multiple images at once\npredict.classify(model, ['/Users/bedapudi/Desktop/2.jpg', '/Users/bedapudi/Desktop/6.jpg'])\n# {'2.jpg': {'sexy': 4.3454795e-05, 'neutral': 0.00026579312, 'porn': 0.0007733498, 'hentai': 0.14751942, 'drawings': 0.8513979}, '6.jpg': {'drawings': 0.004214506, 'hentai': 0.013342537, 'neutral': 0.01834045, 'porn': 0.4431829, 'sexy': 0.5209196}}\n\n# Predict for all images in a directory\npredict.classify(model, '/Users/bedapudi/Desktop/')\n\n```\n\nIf you've installed the package or use the command-line this should work, too...\n\n```sh\n# a single image\nnsfw-predict --saved_model_path mobilenet_v2_140_224 --image_source test.jpg\n\n# an image directory\nnsfw-predict --saved_model_path mobilenet_v2_140_224 --image_source images\n\n# a single image (from code/CLI)\npython3 nsfw_detector/predict.py --saved_model_path mobilenet_v2_140_224 --image_source test.jpg\n\n```\n\n\n## Download\nPlease feel free to use this model to help your products!  \n\nIf you'd like to [say thanks for creating this, I'll take a donation for hosting costs](https://www.paypal.me/GantLaborde).\n\n# Latest Models Zip (v1.1.0)\nhttps://github.com/GantMan/nsfw_model/releases/tag/1.1.0\n\n### Original Inception v3 Model (v1.0)\n* [Keras 299x299 Image Model](https://s3.amazonaws.com/ir_public/ai/nsfw_models/nsfw.299x299.h5)\n* [TensorflowJS 299x299 Image Model](https://s3.amazonaws.com/ir_public/ai/nsfw_models/nsfwjs.zip)\n* [TensorflowJS Quantized 299x299 Image Model](https://s3.amazonaws.com/ir_public/ai/nsfw_models/min_nsfwjs.zip)\n* [Tensorflow 299x299 Image Model](https://s3.amazonaws.com/ir_public/ai/nsfw_models/nsfw.299x299.pb) - [Graph if Needed](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#inspecting-graphs)\n\n### Original Mobilenet v2 Model (v1.0)\n* [Keras 224x224 Image Model](https://s3.amazonaws.com/ir_public/nsfwjscdn/nsfw_mobilenet2.224x224.h5)\n* [TensorflowJS 224x224 Image Model](https://s3.amazonaws.com/ir_public/nsfwjscdn/TFJS_nsfw_mobilenet/tfjs_nsfw_mobilenet.zip)\n* [TensorflowJS Quantized 224x224 Image Model](https://s3.amazonaws.com/ir_public/nsfwjscdn/TFJS_nsfw_mobilenet/tfjs_quant_nsfw_mobilenet.zip)\n* [Tensorflow 224x224 Image Model](https://s3.amazonaws.com/ir_public/nsfwjscdn/TF_nsfw_mobilenet/nsfw_mobilenet.pb) - [Graph if Needed](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#inspecting-graphs)\n* [Tensorflow Quantized 224x224 Image Model](https://s3.amazonaws.com/ir_public/nsfwjscdn/TF_nsfw_mobilenet/quant_nsfw_mobilenet.pb) - [Graph if Needed](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#inspecting-graphs)\n\n## PyTorch Version\nKudos to the community for creating a PyTorch version with resnet!\nhttps://github.com/yangbisheng2009/nsfw-resnet\n\n## TF1 Training Folder Contents\nSimple description of the scripts used to create this model:\n* `inceptionv3_transfer/` - Folder with all the code to train the Keras based Inception v3 transfer learning model.  Includes `constants.py` for configuration, and two scripts for actual training/refinement.\n* `mobilenetv2_transfer/` - Folder with all the code to train the Keras based Mobilenet v2 transfer learning model.\n* `visuals.py` - The code to create the confusion matrix graphic\n* `self_clense.py` - If the training data has significant inaccuracy, `self_clense` helps cross validate errors in the training data in reasonable time.   The better the model gets, the better you can use it to clean the training data manually.\n\n_e.g._\n```bash\ncd training\n# Start with all locked transfer of Inception v3\npython inceptionv3_transfer/train_initialization.py\n\n# Continue training on model with fine-tuning\npython inceptionv3_transfer/train_fine_tune.py\n\n# Create a confusion matrix of the model\npython visuals.py\n```\n\n## Extra Info\nThere's no easy way to distribute the training data, but if you'd like to help with this model or train other models, get in touch with me and we can work together.\n\nAdvancements in this model power the quantized TFJS module on https://nsfwjs.com/\n\nMy Twitter is [@GantLaborde](https://twitter.com/GantLaborde) - I'm a School Of AI Wizard New Orleans.  I run the twitter account [@FunMachineLearn](https://twitter.com/FunMachineLearn)\n\nLearn more about [me](http://gantlaborde.com/) and the [company I work for](https://infinite.red/).\n\nSpecial thanks to the [nsfw_data_scraper](https://github.com/alexkimxyz/nsfw_data_scrapper) for the training data.  If you're interested in a more detailed analysis of types of NSFW images, you could probably use this repo code with [this data](https://github.com/EBazarov/nsfw_data_source_urls).\n\nIf you need React Native, Elixir, AI, or Machine Learning work, check in with us at [Infinite Red](https://infinite.red/), who make all these experiments possible.  We're an amazing software consultancy worldwide!\n\n## Cite\n```\n@misc{man,\n  title={Deep NN for NSFW Detection},\n  url={https://github.com/GantMan/nsfw_model},\n  journal={GitHub},\n  author={Laborde, Gant}}\n```\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n| [\u003cimg src=\"https://avatars0.githubusercontent.com/u/997157?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGant Laborde\u003c/b\u003e\u003c/sub\u003e](http://gantlaborde.com/)\u003cbr /\u003e[💻](https://github.com/GantMan/nsfw_model/commits?author=GantMan \"Code\") [📖](https://github.com/GantMan/nsfw_model/commits?author=GantMan \"Documentation\") [🤔](#ideas-GantMan \"Ideas, Planning, \u0026 Feedback\") | [\u003cimg src=\"https://avatars2.githubusercontent.com/u/15898654?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBedapudi Praneeth\u003c/b\u003e\u003c/sub\u003e](http://bpraneeth.com)\u003cbr /\u003e[💻](https://github.com/GantMan/nsfw_model/commits?author=bedapudi6788 \"Code\") [🤔](#ideas-bedapudi6788 \"Ideas, Planning, \u0026 Feedback\") |\n| :---: | :---: |\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n","funding_links":["https://www.paypal.me/GantLaborde"],"categories":["Python","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGantMan%2Fnsfw_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGantMan%2Fnsfw_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGantMan%2Fnsfw_model/lists"}