Code Monkey home page Code Monkey logo

porndetector's Introduction

PornDetector

Two python porn images (nudity) detectors.

First one (pcr.py) use scikit-learn and opencv. I was able to get ~85% accuracy on markup with 1500 positive and 1500 negative samples. It use two machine-learned classifiers - one of them use HSV colors histogram, and another use SIFT descriptors.

Second one (nnpcr.py) uses tensorflow neural network. I was able to get ~90% accuracy on the same markup. It use 4 convolutional (3x3 filters) combined with max_pool (2x2) layers, one 1024 fully connected layer and a softmax classifier at the end.

Requirements of opencv & sklearn detector

  • python 2.7
  • scikit-learn 0.15
  • opencv 2.4 (build it from sources, cause it missing SIFT by default)

Requirements of tensorlflow detector

  • python 2.7
  • opencv 2.4 (you can take binary from repository)
  • latest tensorflow

This is my configuration, may be it can work with another library versions.

Usage of opencv & sklearn detector

  • Url prediction demo: ./pcr.py url http://example.com/img.jpg
  • Code usage:
from pcr import PCR
model = PCR()
model.loadModel('model.bin')
predictions = model.predict(['image1.jpg', 'image2.jpg', 'image3.jpg'])
print predictions

Usage of tensorlflow detector

  • Url prediction demo: ./nnpcr.py url http://example.com/img.jpg
  • Code usage:
from nnpcr import NNPCR
model = NNPCR()
model.loadModel('nnmodel.bin')
predictions = model.predict(['image1.jpg', 'image2.jpg', 'image3.jpg'])
print predictions

Train model

  • create directory 1 (with non-porn images), 2 (with porn images), cache (empty)
  • Run ./pcr.py train (to train opencv & sklearn) or ./nnpcr.py train (for tensorflow one).

After train finish you will see accuracy and you will get "model.bin" file with your trained model. Now you can use it to detect porn (see functions predictTest and predictUrl). I added a sample model (model.bin) - you can test it without training your own model, but I recomend you to gather some huge collection of images (eg, 50K) for best results.

License

Public domain (but it may use some patented algorithms, eg. SIFT - so you should check license of all used libraries).

porndetector's People

Contributors

bakwc avatar dakra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.