• Stars
    star
    427
  • Rank 99,106 (Top 2 %)
  • Language
    Python
  • License
    Other
  • Created about 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tensorflow Implementation of Yahoo's Open NSFW Model

Tensorflow Implementation of Yahoo's Open NSFW Model

This repository contains an implementation of Yahoo's Open NSFW Classifier rewritten in tensorflow.

The original caffe weights have been extracted using Caffe to TensorFlow. You can find them at data/open_nsfw-weights.npy.

Prerequisites

All code should be compatible with Python 3.6 and Tensorflow 1.x (tested with 1.12). The model implementation can be found in model.py.

Usage

> python classify_nsfw.py -m data/open_nsfw-weights.npy test.jpg

Results for 'test.jpg'
	SFW score:	0.9355766177177429
	NSFW score:	0.06442338228225708

Note: Currently only jpeg images are supported.

classify_nsfw.py accepts some optional parameters you may want to play around with:

usage: classify_nsfw.py [-h] -m MODEL_WEIGHTS [-l {yahoo,tensorflow}]
                        [-t {tensor,base64_jpeg}]
                        input_jpeg_file

positional arguments:
  input_file            Path to the input image. Only jpeg images are
                        supported.

optional arguments:
  -h, --help            show this help message and exit
  -m MODEL_WEIGHTS, --model_weights MODEL_WEIGHTS
                        Path to trained model weights file
  -l {yahoo,tensorflow}, --image_loader {yahoo,tensorflow}
                        image loading mechanism
  -i {tensor,base64_jpeg}, --input_type {tensor,base64_jpeg}
                        input type

-l/--image-loader

The classification tool supports two different image loading mechanisms.

  • yahoo (default) replicates yahoo's original image loading and preprocessing. Use this option if you want the same results as with the original implementation
  • tensorflow is an image loader which uses tensorflow exclusively (no dependencies on PIL, skimage, etc.). Tries to replicate the image loading mechanism used by the original caffe implementation, differs a bit though due to different jpeg and resizing implementations. See this issue for details.

Note: Classification results may vary depending on the selected image loader!

-i/--input_type

Determines if the model internally uses a float tensor (tensor - [None, 224, 224, 3] - default) or a base64 encoded string tensor (base64_jpeg - [None, ]) as input. If base64_jpeg is used, then the tensorflow image loader will be used, regardless of the -l/--image-loader argument.

Tools

The tools folder contains some utility scripts to test the model.

create_predict_request.py

Takes an input image and generates a json file suitable for prediction requests to a Open NSFW Model deployed with Google Cloud ML Engine (gcloud ml-engine predict) or tensorflow-serving.

export_savedmodel.py

Exports the model using the tensorflow serving export api (SavedModel). The export can be used to deploy the model on Google Cloud ML Engine, Tensorflow Serving or on mobile (haven't tried that one yet).

export_tflite.py

Exports the model in TFLite format. Use this one if you want to run inference on mobile or IoT devices. Please note that the base64_jpeg input type does not work with TFLite since the standard runtime lacks a number of required tensorflow operations.

export_graph.py

Exports the tensorflow graph and checkpoint. Freezes and optimizes the graph per default for improved inference and deployment usage (e.g. Android, iOS, etc.). Import the graph with tf.import_graph_def.

More Repositories

1

yolo-tiny-v1-mobile

Yolo for Android and iOS - Mobile Deep Learning Object Detection in Realtime written in Kotlin and Swift
Jupyter Notebook
95
star
2

gradle-offline-dependencies-plugin

Store project dependencies alongside your code for reproducible offline builds
Groovy
84
star
3

vgg16-transfer-learning

Transfer learning powered by tensorflow and Vgg16
Jupyter Notebook
12
star
4

androguard-protobuf-nano-extractor

Androguard script to extract protobuf definitions
Python
8
star
5

advanced-ir-search_engine

Python-based text search engine from scratch supporting multiple document similarity metrics (TF-IDF, BM25, BM25VA)
Python
6
star
6

ir-search-engine-rust

Rust-based text search engine from scratch supporting multiple document similarity metrics (TF-IDF, BM25, BM25VA)
Rust
5
star
7

tfhub-exporter

Export and optimize Tensorflow Hub models for inference and deployment
Jupyter Notebook
4
star
8

objc-murmur3-bloomfilter

Bloom filter implementation using murmur3 hashing written in Objective-C
Objective-C
3
star
9

advanced-ir-mir

Music similarity and feature extraction experiments
Jupyter Notebook
2
star
10

digitalpreservation-repo-migration

CKAN to DSpace Migration Tool
Python
1
star
11

psmove-api-example

C#
1
star
12

ratpack-webapp-template

ratpack.io webapplication template
Java
1
star
13

psmoveapi_csharp-osx-bundle

OSX library bundle for the psmoveapi C# bindings
C
1
star
14

xai-statlog-heart

Exploration of ML Explainability Methods on the Statlog (Heart) Data Set
Jupyter Notebook
1
star
15

digitalpreservation-dmp-generator

Automatic DMP Generator
JavaScript
1
star