Coder Social home page Coder Social logo

dl4j_human_remover's Introduction

Automatic Human removal in photo using Image Segmentation in Deep Learning (dl4j) + Seam Carving Algorithm in Java

Animated Demo

Demo

Before And After

How to run

Docker

docker is probably the easiest way to run this, so you do not have to download the model manually

# pull the image from DockerHub
docker pull tonykwok1992/dl4j-human-remover:1.0.0

# OR, Building the docker image, will take a while for the first time to download all dependencies
docker build . -t tonykwok1992/dl4j-human-remover:1.0.0
# Run it as web server
docker run --rm -p 5000:5000 tonykwok1992/dl4j-human-remover:1.0.0

Test out your image:

  • Go to your browser at http://localhost:5000. The Web UI will allow you to upload a photo for testing

  • If you want to do it via command line, via curl

curl http://localhost:5000/api/removehuman --data-binary "@/path_to_image/image.jpg" --output /output_path/output.jpg

# where /path_to_image/image.jpg is the input and /output_path/output.jpg is the output file you want it to be located at

Intellij

Download the model at http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz and extract it. Set environment variable MODEL_PATH to be where the extracted frozen_inference_graph.pb is at

How it works

Automatic human removal is essentially solving 2 problems.

  1. Detect a human from photos
  2. Remove an object from photos without distorting the photo

Point 1 is solved by the power of deep learning while point 2 is solved by traditional computer vision algorithm

1. Image segmentation using deep learning

This project imports a Deep Learning Image segmentation model (MobileNet) pre-trained on Tensorflow (http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_train_aug_2018_01_29.tar.gz) to Deeplearning4j (nd4j) for detecting human from the photo

Input:

Output as Mask:

2. Content-aware image resizing in Computer Vision (Seam Carving Algorithm)

With the masked area detected, we make use of Seam Carving Algorithm (https://en.wikipedia.org/wiki/Seam_carving) with energy in the masked area set to zero so that all seams will pass through the mask area during the downsizing. After all masked area removed, we will be (content-aware) upsizing the image again using the same algorithm.

References

https://en.wikipedia.org/wiki/Seam_carving

https://github.com/PacktPublishing/OpenCV-with-Python-By-Example/blob/master/Chapter07/object_removal.py

More examples

Ideas / Improvement

My original thought before discovering Seam Carving Algorithm is to use Deep Learning for Generative inpainting too (e.g. https://github.com/JiahuiYu/generative_inpainting). However, I found that it is not always that straightforward to port Tensorflow model to nd4j if it isn't already in frozen graph format. Therefore I've turned to traditional Computer Vision algorithm and find Seam Carving, which surprisingly produce a better result visually on my few testing images.

Feel free to submit Pull requests for idea contribution

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.