All Projects → SashiDo → content-moderation-image-api

SashiDo / content-moderation-image-api

Licence: Apache-2.0 license
An NSFW Image Classification REST API for effortless Content Moderation built with Node.js, Tensorflow, and Parse Server

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to content-moderation-image-api

nsfw-classification-tensorflow
NSFW classify model implemented with tensorflow.
Stars: ✭ 58 (+16%)
Mutual labels:  nsfw, tensorflow-js, nsfw-recognition
parse server dart
Parse Server SDK for dart and flutter
Stars: ✭ 25 (-50%)
Mutual labels:  parse-server, parse-sdk
Ml Classifier Ui
A UI tool for quickly training image classifiers in the browser
Stars: ✭ 224 (+348%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+38230%)
Mutual labels:  parse-server, parse-platform
generative-art
🌈🎨 Generative Art is the idea realized as genetic code of artificial events, as construction of dynamic complex systems able to generate endless variations. This is also a nuxt-module (@luxdamore/nuxt-canvas-sketch) - [three.js, tensorflow.js and gsap are not included].
Stars: ✭ 41 (-18%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Cs224d
Code for Stanford CS224D: deep learning for natural language understanding
Stars: ✭ 222 (+344%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Parse Dashboard
A dashboard for managing your Parse Server Apps
Stars: ✭ 3,534 (+6968%)
Mutual labels:  parse-server, parse-platform
Androidtensorflowmachinelearningexample
Android TensorFlow MachineLearning Example (Building TensorFlow for Android)
Stars: ✭ 1,369 (+2638%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
deep-learning-in-s4tf
Get started with Swift for TensorFlow by examples
Stars: ✭ 31 (-38%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
tf-examples
TensorFlow examples
Stars: ✭ 23 (-54%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
teaching-nodejs-expressjs-framework-spring-2019-2020
Complete Node-Express Application
Stars: ✭ 16 (-68%)
Mutual labels:  node-js, express-js
Yolov3 Tf2
YoloV3 Implemented in Tensorflow 2.0
Stars: ✭ 2,327 (+4554%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Tensorflow In Practice Code
源码实现:《TensorFlow实战》黄文坚,唐源 著
Stars: ✭ 176 (+252%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Nakedtensor
Bare bone examples of machine learning in TensorFlow
Stars: ✭ 2,443 (+4786%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Chatgirl
ChatGirl is an AI ChatBot based on TensorFlow Seq2Seq Model. ChatGirl 一个基于 TensorFlow Seq2Seq 模型的聊天机器人。(包含预处理过的 twitter 英文数据集,训练,运行,工具代码,来波 Star 。)QQ群:167122861
Stars: ✭ 105 (+110%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
parse-stack
Parse Server Ruby Client SDK
Stars: ✭ 59 (+18%)
Mutual labels:  parse-server, parse-sdk
HIMS
Hospital Information Management System create using Node Js
Stars: ✭ 41 (-18%)
Mutual labels:  node-js, express-js
Free Tensorflow
Tensorflow 免费中文视频教程,开源代码,免费书籍.
Stars: ✭ 83 (+66%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Ml Classifier
A tool for quickly training image classifiers in the browser
Stars: ✭ 97 (+94%)
Mutual labels:  tensorflow-tutorials, tensorflow-examples
Parse Server Example
Example server using Express and the parse-server module.
Stars: ✭ 1,807 (+3514%)
Mutual labels:  parse-server, parse-platform

Ready-to-use Node.JS REST API for classification of indecent images.

Machine Learning has already matured to the point where it should be a vital part of projects of all sizes. Advances in computer processing power, storage, data tools, web, etc made machine learning technologies to become more and more affordable. This and the constant strive for innovation, led SashiDo's team to create a fully-functional Content Moderation Service with React based Admin Panel built with Open-Source tools and libraries only. The result is a simple and elegant product, which is easy to maintain, can be integrated into any Node.JS project and hosted anywhere. One at a time, we will share all three layers of the Content moderation service - API, Automation Engine and beautiful Admin Panel. The content moderation REST API is just the first chunk.

Examples & Demos

These are the examples and the demos of what you'll have in your tools set after you deploy and integrate this repo in your projects. We've prepared examples only for some of the classes. For the other classes we think you should experiment by yourself ... you know what I mean ;).

Image Source Image Source Image Source
Classification Result Classification Result Classification Result
[{
  "className": "Neutral",
  "probability": 0.93821
}, {
  "className": "Drawing",
  "probability": 0.05473
}, {
  "className": "Sexy",
  "probability": 0.00532
}, {
  "className": "Hentai",
  "probability": 0.00087
}, {
  "className": "Porn",
  "probability": 0.00085
}]
[{
  "className": "Sexy",
  "probability": 0.99394
}, {
  "className": "Neutral",
  "probability": 0.00432
}, {
  "className": "Porn",
  "probability": 0.00164
}, {
  "className": "Drawing",
  "probability": 0.00006
}, {
  "className": "Hentai",
  "probability": 0.00001
}]
[{
  "className": "Drawing",
  "probability": 0.96063
}, {
  "className": "Neutral",
  "probability": 0.03902
}, {
  "className": "Hentai",
  "probability": 0.00032
}, {
  "className": "Sexy",
  "probability": 0.00001
}, {
  "className": "Porn",
  "probability": 0.00005
}]
Neutral Demo Sexy Demo Drawing Demo

How it works

This REST API is built in Node.JS with Mongo DB and Parse Server. Classifying images may be invoked from an Express route or a Cloud Code function ( Parse Server lovers, you're welcome :) )

We have implemented NSFW.JS classification, which uses TensorFlowJS pretrained models.

Classification map

Pass the API an image and receive a JSON response, which holds the predictions on how likely this image falls into each of the following classes:

Drawing - Harmless art, or picture of art
Hentai - Pornographic art, unsuitable for most work environments
Neutral - General, inoffensive content
Porn - Indecent content and actions, often involving genitalia
Sexy - Unseemly provocative content, can include nipples

File Structure

The REST API is built on top of Parse Server. You can use it in a standard Express app, but keep in mind that the file structure of the repo is Parse specific. The code is organized in a src folder and src/cloud/main.js is the root file for the service. For more information about how the project is building on the Local env and in Production, take a look at the package.json

Installation & Configuration

Requirements:

  • Node.JS >= 10.2.1

  • Mongo DB

Download the project

Clone the repo:

git clone https://github.com/SashiDo/content-moderation-image-api.git
cd content-moderation-image-api

Set Environment Variables

Copy the env.example to .env file and set the environment variables for your local environment with your favorite editor:

cp env.example .env

Place your MongoDB URI. If your app is hosted at SashiDo, you can use the database URI of your SashiDo project. Find the connection string from the app's Dashboard -> App -> App Settings -> Security & Keys

Install Dependencies

As this is a full-featured example, all dependencies are present to the packege.json. You only need to run:

npm install

Start the project

npm run dev

If everything is okay you should see an output similar to this one:

[nodemon] 2.0.4
...
[nodemon] starting `node index index.js`
✨  Built in 2.55s.
node-pre-gyp ...
...
Running on http://localhost:1337
⠙ Building index.js...The NSFW Model was loaded successfuly!
✨  Built in 16.41s.

If you see the output above, you are ready to play with the API :)

API Usage Examples

The project contains two approaches for classifying images - for direct communication through the Parse SDK using Cloud Code and from an Express route.

Classify from the Express endpoint

curl http://localhost:1337/api/image/classify?url=https://nsfw-demo.sashido.io/sexy.png

Classify from a Cloud Code function via Parse SDKs

You can invoke the nsfwImageClassify function from the client-side or using the Parse Server REST API:

Android SDK Example

HashMap<String, String> params = new HashMap<String, String>();
params.put("url", "https://nsfw-demo.sashido.io/sexy.png");
ParseCloud.callFunctionInBackground("nsfwImageClassify", params, new FunctionCallback<Object>() {
  void done(Object predictions, ParseException e) {
    if (e == null) {
      // prediction
    }
  }
});

More information about how to work with the Android SDK can be found in the official docs.

iOS SDK Example

PFCloud.callFunctionInBackground("nsfwImageClassify", withParameters: ["url":"https://nsfw-demo.sashido.io/sexy.png"]) {
  (predictions, error) in
  if !error {
    // prediction
  }
}

More information about how to work with the Parse iOS SDK can be found in the official docs.

REST API Example

curl -X POST \
  -H "X-Parse-Application-Id: myAppId" \
  -H "X-Parse-REST-API-Key: myRestKey" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://nsfw-demo.sashido.io/sexy.png" }' \
  http://localhost:1337/1/functions/nsfwImageClassify

More information about how to work with the Parse REST API can be found in the official docs.

SashiDo users can test all Cloud Code functions from our super-friendly API Console that’s built in the Dashboard. Moreover, it gives you the option to export ay request to cURL.

Deployment on Production

1. Environment Variables Setup

For production, you need to set the NSFW model URL and the NSFW Model Shape size. SashiDo stores three NSFW models, each one you can set easily using the following URLs:

Model URL Size Shape Size Accuracy
https://ml.files-sashido.cloud/models/nsfw_inception_v3/ Huge 299 93%
https://ml.files-sashido.cloud/models/nsfw_mobilenet_v2/90/ 2.6 MB 224 90%
https://ml.files-sashido.cloud/models/nsfw_mobilenet_v2/93/ 4.2 MB 224 93%

Please note the Inception_v3 model used for this projects has high RAM/CPU consumption. While the two mobilenet models are far more lightweight.

Choose the model and set the following environment variables for your live server:

TF_MODEL_URL = MODEL_URL
TF_MODEL_INPUT_SHAPE_SIZE = MODEL_SHAPE_SIZE

# Example
TF_MODEL_URL="https://ml.files-sashido.cloud/models/nsfw_mobilenet_v2/93/"
TF_MODEL_INPUT_SHAPE_SIZE=224

2. Code Deployment

Deployment on SashiDo

This is probably the simplest way to deploy the code in production. At SashiDo we have implemented an automatic git deployment process following the The Twelve Factor App principle.

Connect your SashiDo app with GitHub, check here for more details how to start using GitHub with SashiDo.

Next, the code can be easily deployed with two simple commands for adding a remote branch and pushing the code.

git remote add production [email protected]:parsegroundapps/<your-pg-app-your-app-repo>.git
git push -f production master

Deployment on other providers

Basically, you need to follow the same steps as for SashiDo Deployment. Simply follow the requirements of your hosting provider when setting environment variables for production and deploying the code.

What's next?

To get a further insight into the project and what inspired us to build this service, check out our blog post on the topic here.

The REST API is a part of the Content Moderation service, which also offers:

  • Automation Engine that will automatically delete inappropriate images. Set the params and reduce manual work to the bare minimum. - Coming Soon!

  • Admin Panel where all images in need of moderation are stacked up in a beautiful interface, which allows you to make decisions with just a click. - Coming Soon!

Contribution

Thanks for looking at this section. We’re open to any cool ideas, so if you have one and are willing to share - fork the repo, apply changes and open a pull request. :)

License

Copyright © 2020, CloudStrap AD. See LICENSE for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].