Code Monkey home page Code Monkey logo

opennsfw.js's Introduction

OpenNSFW.js

A nudity classifier for web browsers utilizing Yahoo's OpenNSFW model


Motivation

There are several projects that offer Tensorflow.js NSFW classification, but all of the models I tried had serious training bias against people of color, causing regular false positives due to the subject's skin color. This was highly disturbing and made them completely unusable for the project I was working on (YouTube Spam Remover). After several days of searching, the best model I could find was Yahoo's OpenNSFW. There was not yet a port to Tensorflow.js, and thus this project was born.


Credits

This project stands on the shoulders of giants. A huge thanks to the following for making it possible:

  • Yahoo, for making their Caffe classification model open-source
  • Marc Dietrichstein, for porting OpenNSFW to TensorFlow 1
  • Bosco Yung, for porting the aforementioned TensorFlow model to TensorFlow 2.


Usage:

<script src="opennsfw.min.js"></script>  <!-- Or include it in your bundle -->

<script>
	async function classify_images() {
		const nsfw = new window.OpenNSFW();
		await nsfw.load();

		// this.prime() speeds up subsequent classifications, but it's not helpful
		// here as we're immediately classifying an image after the model loads
		// await opennsfw.prime();

		const images  = document.querySelectorAll('img');		
		const results = await nsfw.classifyImages(images)

		let img_index = 0;
		for (let result of results) {
			const new_text = document.createElement('h4');
			const confidence = (result.nsfw_confidence * 100).toFixed(4);

			new_text.innerText = `${result.is_nsfw ? 'NSFW' : 'SFW'} - (${confidence}%)`;

			images[img_index].parentElement.appendChild(new_text);
			img_index++;
		}
	}

	document.addEventListener('DOMContentLoaded', classify_images);
</script>

<!-- (...) -->

<div><img src="img-1.jpg"></div>
<div><img src="img-2.jpg"></div>

opennsfw.js's People

Contributors

samipfjo avatar

Watchers

 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.