Tool for removing background from image using neural networks
The program removes the background from photos
- Added support for new neural networks (U^2-NET, BASNet) on PyTorch
- Significantly improved output image quality
- Added GUI by @Munawwar
- Tensorflow 2.0 compatible
- All models support processing both on the video card and on the processor
tqdm
progress bar- The program has a lot of methods for image preprocessing and post-processing, which allows you to configure the quality and speed of image processing for your needs
- Removes background from image without loss of image resolution
- The script not only processes a single file, but can also process all images from the input folder and save them in the output folder with the same name
- Implemented support for the neural network from this script and improved the result of its work
โฑ Try this program yourself on Google Colab
None
- No preprocessing methods used.bbd-fastrcnn
(default) - This image pre-processing technique uses two neural networks ($used_model and Fast RCNN) to first detect the boundaries of objects in a photograph, cut them out, sequentially remove the background from each object in turn and subsequently collect the entire image from separate parts.bbmd-maskrcnn
- This image pre-processing technique uses two neural networks ($used_model and Mask RCNN) to first detect the boundaries and masks of objects in a photograph, cut them out, expand the masks by a certain number of pixels, apply them and remove the background from each object in turn and subsequently collect the entire image from separate parts. So far it works very poorly!
No
- No post-processing methods used.rtb-bnb
(default) - This algorithm improves the boundaries of the image obtained from the neural network. It is based on the principle of removing too transparent pixels and smoothing the borders after removing too transparent pixels.rtb-bnb2
- This algorithm improves the boundaries of the image obtained from the neural network. It is based on the principle of removing too transparent pixels and smoothing the borders after removing too transparent pixels. The algorithm performs this procedure twice. For the first time, the algorithm processes the image from the neural network, then sends the processed image back to the neural network, and then processes it again and returns it to the user. This method gives the best result in combination with u2net without any preprocessing methods.
- See
requirements.txt
Note: You can choose what to install PyTorch or TensorFlow, based on which model you want to use.
PyTorch foru2net
,u2netp
TensorFlow forxception_model
,mobile_net_model
Mxnet and Gluoncv are used for image preprocessing methods and are installed optionally.
Also, to speed up image processing by performing all the calculations on the video card, install separately special versions of the dependencies (tensorflow, torch, mxnet, gluoncv and others
) designed to work with your video card.
TensorFlow models are not recommended for use, since these models have much worse quality and lower image processing speed, also these models are designed solely to remove the background from portrait photos and photos with animals.
- Clone this repository
- Install all the dependencies from requirements.txt via
pip3 install -r requirements.txt
- Run
./setup.bat
This setup.bat script loads the trained model.
- Clone repository:
git clone https://github.com/OPHoperHPO/image-background-remove-tool
- Install all the dependencies from requirements.txt:
pip3 install -r requirements.txt
- Run
./setup.sh
and select the model you need. This setup.sh script loads the pre-trained model.
python3 gui.py
python3 main.py -i <input_path> -o <output_path> -m <model_type> -prep <preprocessing_method> -postp <postprocessing_method>
-i <input_path>
- path to input file or dir.-o <output_path>
- path to output file or dir.-prep <preprocessing_method>
- Preprocessing method. Can bebbd-fastrcnn
orbbmd-maskrcnn
orNone
.bbd-fastrcnn
is better to use.-postp <postprocessing_method>
- Postprocessing method. Can bertb-bnb
orrtb-bnb2
orNo
.rtb-bnb
is better to use.-m <model_type>
- can beu2net
orbasnet
oru2netp
orxception_model
ormobile_net_model
.u2net
is better to use.
DeepLab models (xception_model
ormobile_net_model
) are outdated and designed to remove the background from PORTRAIT photos or PHOTOS WITH ANIMALS!
More info about models.
Note: See example scripts for more information on using the program.
1) Check TODOs in code.
2) Implement support for Mask RCNN. (90% done)
๐ช Credits: More info
You can thank me for developing any of my projects, provide financial support for developing new projects and buy me a small cup of coffee.โ
Just support me on these platforms:
- More sample images in docs/imgs/input/ and docs/imgs/examples/ folders.
Examples of images from the background are contained in folders in the following format:{model_name}/{preprocessing_method_name}/{postprocessing_method_name}
- Input:
- Output(u2net/bbd-fastrcnn/rtb-bnb):
- Output(basnet/bbd-fastrcnn/rtb-bnb):
- Output(u2netp/bbd-fastrcnn/rtb-bnb):
- Output(xception_model/bbd-fastrcnn/rtb-bnb):
- Output(mobile_net_model/bbd-fastrcnn/rtb-bnb):