All Projects → MaybeShewill-CV → nsfw-classification-tensorflow

MaybeShewill-CV / nsfw-classification-tensorflow

Licence: other
NSFW classify model implemented with tensorflow.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to nsfw-classification-tensorflow

nsfw api
Python REST API to detect images with adult content
Stars: ✭ 71 (+22.41%)
Mutual labels:  image-classification, nsfw, nsfw-recognition
content-moderation-image-api
An NSFW Image Classification REST API for effortless Content Moderation built with Node.js, Tensorflow, and Parse Server
Stars: ✭ 50 (-13.79%)
Mutual labels:  nsfw, tensorflow-js, nsfw-recognition
Nsfwjs
NSFW detection on the client-side via TensorFlow.js
Stars: ✭ 5,223 (+8905.17%)
Mutual labels:  tensorflow-js, nsfw-recognition
serving-tensorflow-models
Serving TensorFlow models with TensorFlow Serving 📙
Stars: ✭ 41 (-29.31%)
Mutual labels:  image-classification, tensorflow-serving
tensorflow-image-recognition-chrome-extension
Chrome browser extension for using TensorFlow image recognition on web pages
Stars: ✭ 88 (+51.72%)
Mutual labels:  image-classification, tensorflow-js
ML4K-AI-Extension
Use machine learning in AppInventor, with easy training using text, images, or numbers through the Machine Learning for Kids website.
Stars: ✭ 18 (-68.97%)
Mutual labels:  image-classification
Bag-of-Visual-Words
🎒 Bag of Visual words (BoW) approach for object classification and detection in images together with SIFT feature extractor and SVM classifier.
Stars: ✭ 39 (-32.76%)
Mutual labels:  image-classification
VisualML
Interactive Visual Machine Learning Demos.
Stars: ✭ 104 (+79.31%)
Mutual labels:  tensorflow-js
DynamicViT
[NeurIPS 2021] DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification
Stars: ✭ 340 (+486.21%)
Mutual labels:  image-classification
FaceClassification Tensorflow
Building a Neural Network that classifies faces using OpenCV and Tensorflow
Stars: ✭ 37 (-36.21%)
Mutual labels:  image-classification
CNN-Image-Classifier
A Simple Deep Neural Network to classify images made with Keras
Stars: ✭ 65 (+12.07%)
Mutual labels:  image-classification
deep-parking
Code to reproduce 'Deep Learning for Decentralized Parking Lot Occupancy Detection' paper.
Stars: ✭ 81 (+39.66%)
Mutual labels:  image-classification
Poke-Pi-Dex
Our deep learning for computer vision related project for nostalgic poke weebs (Sistemi digitali, Unibo).
Stars: ✭ 18 (-68.97%)
Mutual labels:  image-classification
FNet-pytorch
Unofficial implementation of Google's FNet: Mixing Tokens with Fourier Transforms
Stars: ✭ 204 (+251.72%)
Mutual labels:  image-classification
image-recognition
采用深度学习方法进行刀具识别。
Stars: ✭ 19 (-67.24%)
Mutual labels:  image-classification
ePillID-benchmark
ePillID Dataset: A Low-Shot Fine-Grained Benchmark for Pill Identification (CVPR 2020 VL3)
Stars: ✭ 54 (-6.9%)
Mutual labels:  image-classification
ICCV2021-Paper-Code-Interpretation
ICCV2021/2019/2017 论文/代码/解读/直播合集,极市团队整理
Stars: ✭ 2,022 (+3386.21%)
Mutual labels:  image-classification
pytorch-vit
An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
Stars: ✭ 250 (+331.03%)
Mutual labels:  image-classification
CoreML-and-Vision-with-a-pre-trained-deep-learning-SSD-model
This project shows how to use CoreML and Vision with a pre-trained deep learning SSD (Single Shot MultiBox Detector) model. There are many variations of SSD. The one we’re going to use is MobileNetV2 as the backbone this model also has separable convolutions for the SSD layers, also known as SSDLite. This app can find the locations of several di…
Stars: ✭ 16 (-72.41%)
Mutual labels:  image-classification
Deploy-ML-model
No description or website provided.
Stars: ✭ 57 (-1.72%)
Mutual labels:  image-classification

Nsfw-Classify-Tensorflow

NSFW classify model implemented with tensorflow. Use nsfw dataset provided here https://github.com/alexkimxyz/nsfw_data_scraper Thanks for sharing the dataset with us. You can find all the model details here. Don not hesitate to raise an issue if you're confused with the model.

Installation

This software has only been tested on ubuntu 16.04(x64). Here is the test environment info

OS: Ubuntu 16.04 LTS

GPU: Two GTX 1070TI

CUDA: cuda 9.0

Tensorflow: tensorflow 1.12.0

OPENCV: opencv 3.4.1

NUMPY: numpy 1.15.1

Other required package you may install them by

pip3 install -r requirements.txt

Test model

In this repo I uploaded a pretrained dataset introduced as before, you need to download the pretrained weights_file in folder REPO_ROOT_DIR/model/.

You can test a single image on the trained model as follows

cd REPO_ROOT_DIR
python tools/test_model.py --weights_path model/new_model/nsfw_cls.ckpt-100000
--image_path data/test_data/test_drawing.jpg

The following part will show you how the dataset is well prepared

Train your own model

Data Preparation

First you need to download all the origin nsfw data. Here is the how_to_download_source_data. The training example should be organized like the what you can see in REPO_ROOT_DIR/data/nsfw_dataset_example. Then you should modified the REPO_ROOT_DIR/tools/make_nsfw_dataset.sh with your local nsfw dataset. Then excute the dataset preparation script. That may take about one hour in my local machine. You may enlarge the __C.TRAIN.CPU_MULTI_PROCESS_NUMS in config/global_config.py if you have a powerful cpu to accelerate the prepare process.

cd REPO_ROOT_DIR
bash tools/make_nsfw_dataset.sh

The image of each subclass will be split into three part according to the ratio training : validation : test = 0.75 : 0.1 : 0.15. All the image will be convert into tensorflow format record for efficient importing data pipline.

Train Model

The model support multi-gpu training. If you want to training the model on multiple gpus you need to first adjust the __C.TRAIN.GPU_NUM in config/global_config.py file. Then excute the multi-gpu training procedure as follows:

cd REPO_ROOT_DIR
python tools/train_nsfw.py --dataset_dir PATH/TO/PREPARED_NSFW_DATASET --use_multi_gpu True

If you want to train the model from last snap shot you may excute following command:

cd REPO_ROOT_DIR
python tools/train_nsfw.py --dataset_dir PATH/TO/PREPARED_NSFW_DATASET 
--use_multi_gpu True --weights_path PATH/TO/YOUR/LAST_CKPT_FILE_PATH

You may set the --use_multi_gpu False then the whole training process will be excuted on single gpu.

The main model's hyperparameter are as follows:

iterations nums: 160010

learning rate: 0.1

batch size: 32

origin image size: 256

cropped image size: 224

training example nums: 159477

testing example nums: 31895

validation example nums: 21266

The rest of the hyperparameter can be found here.

If you want to convert the downloaded ckpt model into tensorflow saved model you can simply modify the file path in ROOT_DIR/tools/export_nsfw_saved_model.sh and run it.

bash tools/export_nsfw_saved_model.sh

You may monitor the training process using tensorboard tools

During my experiment the train loss drops as follows:
train_loss

The train_top_1_error drops as follows:
train_top_1_error

The validation loss drops as follows:
validation_loss

The validation_top_1_error drops as follows:
validation_top_1_error

The Model Evaluation

You can evaluate the model's performance on the nsfw dataset prepared in advance as follows

cd REPO_ROOT_DIR
python tools/evaluate_nsfw.py --weights_path model/new_model/nsfw_cls.ckpt-160000
--dataset_dir PATH/TO/YOUR/NSFW_DATASET

After you run the script you should see something like this evaluation_result

The model's main evaluation index are as follows:

Precision: 0.92406 with average weighted on each class

Recall: 0.92364 with average weighted on each class

F1 score: 0.92344 with average weighted on each class

The Confusion_Matrix is as follows:
confusion_matrix

The Precison_Recall is as follows:
precision_recall

Online demo

URL: https://maybeshewill-cv.github.io/nsfw_classification

Since tensorflo-js is well supported the online deep learning is easy to deploy. Here I have make a online demo to do local nsfw classification work. The whole js work can be found here https://github.com/MaybeShewill-CV/MaybeShewill-CV.github.io/tree/master/nsfw_classification I have supplied a tool to convert the trained tensorflow saved model file into tensorflow js model file. In order to generate saved model you can read the description about it above. After you generate the tensorflow saved model you can simply modify the file path and run the following script

cd ROOT_DIR
bash tools/convert_tfjs_model.sh

The online demo's example are as follows: online_demo

TODO

  • Add tensorflow serving script
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].