Package: nsfw-detector
NSFW Detection Machine Learning ModelTrained on 60+ Gigs of data to identify:drawings- safe for work drawings (including anime)hentai- hentai and pornographic drawingsneutral- safe for work neutral imagesporn- pornographic images, sexual actssexy- sexually explicit images, not pornographyThis model powersNSFW JS-More InfoCurrent Status:93% Accuracy with the following confusion matrix, based on Inception V3.Review the_artfolder for previous incarnations of this model.Requirements:keras (tested with versions > 2.0.0)
tensorflow >= 2.1.0UsageFor programmatic use of the library.fromnsfw_detectorimportpredictmodel=predict.load_model('./nsfw_mobilenet2.224x224.h5')# Predict single imagepredict.classify(model,'2.jpg')# {'2.jpg': {'sexy': 4.3454722e-05, 'neutral': 0.00026579265, 'porn': 0.0007733492, 'hentai': 0.14751932, 'drawings': 0.85139805}}# Predict multiple images at oncepredict.classify(model,['/Users/bedapudi/Desktop/2.jpg','/Users/bedapudi/Desktop/6.jpg'])# {'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}}# Predict for all images in a directorypredict.classify(model,'/Users/bedapudi/Desktop/')If you've installed the package or use the command-line this should work, too...# a single imagensfw-predict--saved_model_pathmobilenet_v2_140_224--image_sourcetest.jpg# an image directorynsfw-predict--saved_model_pathmobilenet_v2_140_224--image_sourceimages# a single image (from code/CLI)python3nsfw_detector/predict.py--saved_model_pathmobilenet_v2_140_224--image_sourcetest.jpgDownloadPlease feel free to use this model to help your products!If you'd like tosay thanks for creating this, I'll take a donation for hosting costs.Latest Models Zip (v1.1)https://github.com/GantMan/nsfw_model/releases/tag/1.1.0Original Inception v3 Model (v1.0)Keras 299x299 Image ModelTensorflowJS 299x299 Image ModelTensorflowJS Quantized 299x299 Image ModelTensorflow 299x299 Image Model-Graph if NeededOriginal Mobilenet v2 Model (v1.0)Keras 224x224 Image ModelTensorflowJS 224x224 Image ModelTensorflowJS Quantized 224x224 Image ModelTensorflow 224x224 Image Model-Graph if NeededTensorflow Quantized 224x224 Image Model-Graph if NeededPyTorch VersionKudos to the community for creating a PyTorch version with resnet!https://github.com/yangbisheng2009/nsfw-resnetTraining Folder ContentsSimple description of the scripts used to create this model:inceptionv3_transfer/- Folder with all the code to train the Keras based Inception v3 transfer learning model.  Includesconstants.pyfor configuration, and two scripts for actual training/refinement.mobilenetv2_transfer/- Folder with all the code to train the Keras based Mobilenet v2 transfer learning model.visuals.py- The code to create the confusion matrix graphicself_clense.py- If the training data has significant inaccuracy,self_clensehelps 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.e.g.cdtraining# Start with all locked transfer of Inception v3pythoninceptionv3_transfer/train_initialization.py# Continue training on model with fine-tuningpythoninceptionv3_transfer/train_fine_tune.py# Create a confusion matrix of the modelpythonvisuals.pyExtra InfoThere'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.Advancements in this model power the quantized TFJS module onhttps://nsfwjs.com/My twitter is@GantLaborde- I'm a School Of AI Wizard New Orleans.  I run the twitter account@FunMachineLearnLearn more aboutmeand thecompany I work for.Special thanks to thensfw_data_scraperfor the training data.  If you're interested in a more detailed analysis of types of NSFW images, you could probably use this repo code withthis data.If you need React Native, Elixir, AI, or Machine Learning work, check in with us atInfinite Red, who make all these experiments possible.  We're an amazing software consultancy worldwide!Cite@misc{man,
  title={Deep NN for NSFW Detection},
  url={https://github.com/GantMan/nsfw_model},
  journal={GitHub},
  author={Laborde, Gant}}ContributorsThanks goes to these wonderful people (emoji key):Gant Laborde💻📖🤔Bedapudi Praneeth💻🤔This project follows theall-contributorsspecification. Contributions of any kind welcome!Changes1.1.1break out numpy (nd array) functionremove classic app run modes for argparseone more example in README for runningturn down verbosity in image load via filefix requirements for clean system (needs PIL)1.1.0update to tensorflow 2.1.0 and updated mobilenet-based model1.0.0initial creation