Giter Site home page Giter Site logo

ap2amr / ai-background-remove Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ddemmer1/ai-background-remove

0.0 0.0 0.0 12 MB

Cut out objects and remove backgrounds from pictures with artificial intelligence

Python 52.69% Jupyter Notebook 47.31%

ai-background-remove's Introduction

Remove backgrounds and cut out objects from pictures with AI

This works by first detecting objects with Detectron2 , then cutting out the desired masks with openCV and cropping out the object to its bounding boxes.

Detectron2 is Facebook AI Research's next generation software system that implements state-of-the-art object detection algorithms. There is no GPU required if you use pretrained models

List of currently supported objects

The extracted objects are not cut out pixel-perfect, but it can be a tremendous workload reduction to be able to process thousands of images at once. For example as a data set for other ML applications.

Installation

-1. Installing Detectron2 on Linux systems is pretty straightforward.

For Windows 10, a relatively easy solution is to install the Windows subsystem for Linux, instructions here: https://docs.microsoft.com/en-us/windows/wsl/install-win10. You will have to install the following packages as well (in the shell): python, python-dev and opencv-python.

For OS X, you can try to follow the Anaconda instructions posted here: https://medium.com/deepvisionguru/how-to-embed-detectron2-in-your-computer-vision-project-817f29149461. Please note that this is not yet compatible with our demo.py script, we hope to fix that soon.

  1. Clone this repository and enter folder (or download, extract and enter folder):
git clone https://github.com/DDemmer1/ai-background-remove.git
cd ai-background-remove
  1. Create virtual environment to make sure we don't mess with your system python install and install all needed packages:

If you have a Conda python install, try this:

conda create --nsame detectron2
conda activate detectron2

For vanilla python, try this:

python -m venv detectron2
source detectron2/bin/activate
pip install -r detectron2/requirements.txt
  1. Install precompiled Detectron2 with CPU support only:
pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/index.html

OR: Install precompiled Detectron2 for CUDA 10.1:

pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/index.html
  1. Create a new Jupyter kernel which uses the virtual environment you have just created:
ipython kernel install --user --name=detectron2

Run the pretrained model

  1. Copy your images with the objects to extract to ai-background-remove/input

  2. Run the following network: (If you use a Python version other than 3.7. Make sure to change the version in the path )

python detectron2/demo.py --config-file detectron2/lib/python3.7/site-packages/detectron2/model_zoo/configs/COCO-PanopticSegmentation/panoptic_fpn_R_101_3x.yaml --input input/* --output output  --opts MODEL.DEVICE cpu MODEL.WEIGHTS detectron2://COCO-PanopticSegmentation/panoptic_fpn_R_101_3x/139514519/model_final_cafdb1.pkl
  1. Detected objects are marked and a visualization is saved in your /output folder.

Object Extraction

Run Jupyter notebook

jupyter notebook

For background removal open bg-remove.ipynb and make sure the 'detectron2' kernel is used and run the cells

If you want to instead analyse your input corpus open deep_watching.ipynb and run the cells (make sure the 'detectron2' kernel is used)

If you want to know how to label pictures and train your own networks have a look at https://github.com/ghowa/dhd2020

ai-background-remove's People

Contributors

ddemmer1 avatar ghowa 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.