{"id":14979051,"url":"https://github.com/ophoperhpo/image-background-remove-tool","last_synced_at":"2025-10-02T15:30:53.264Z","repository":{"id":37032094,"uuid":"197783491","full_name":"OPHoperHPO/image-background-remove-tool","owner":"OPHoperHPO","description":"✂️ Automated high-quality background removal framework for an image using neural networks. ✂️","archived":false,"fork":true,"pushed_at":"2024-04-27T03:41:17.000Z","size":117006,"stargazers_count":1347,"open_issues_count":7,"forks_count":265,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-09-28T02:21:26.480Z","etag":null,"topics":["background-removal","background-removal-js","basnet","computer-vision","deeplabv3","docker","fastapi","machine-learning","matting","python","pytorch","remove-background","salient-object-detection","segmentation","torch","transfer-learning","trimap","u2net"],"latest_commit_sha":null,"homepage":"https://carve.photos","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"susheelsk/image-background-removal","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OPHoperHPO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-07-19T14:08:00.000Z","updated_at":"2024-09-26T11:29:23.000Z","dependencies_parsed_at":"2023-02-16T02:01:01.053Z","dependency_job_id":null,"html_url":"https://github.com/OPHoperHPO/image-background-remove-tool","commit_stats":{"total_commits":309,"total_committers":15,"mean_commits":20.6,"dds":0.6472491909385114,"last_synced_commit":"2935e4655d2c0260195e22ac08af6c43b5969fdd"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OPHoperHPO%2Fimage-background-remove-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OPHoperHPO%2Fimage-background-remove-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OPHoperHPO%2Fimage-background-remove-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OPHoperHPO%2Fimage-background-remove-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OPHoperHPO","download_url":"https://codeload.github.com/OPHoperHPO/image-background-remove-tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219875832,"owners_count":16554706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["background-removal","background-removal-js","basnet","computer-vision","deeplabv3","docker","fastapi","machine-learning","matting","python","pytorch","remove-background","salient-object-detection","segmentation","torch","transfer-learning","trimap","u2net"],"created_at":"2024-09-24T13:59:03.038Z","updated_at":"2025-10-02T15:30:51.900Z","avatar_url":"https://github.com/OPHoperHPO.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cp align=\"center\"\u003e ✂️ CarveKit ✂️  \u003c/p\u003e\n\n\u003cp align=\"center\"\u003e \u003cimg src=\"docs/imgs/logo.png\"\u003e \u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/OPHoperHPO/image-background-remove-tool/actions/workflows/master_docker.yaml/badge.svg\"\u003e\n\u003cimg src=\"https://github.com/OPHoperHPO/image-background-remove-tool/actions/workflows/master.yml/badge.svg\"\u003e\n\u003ca href=\"https://colab.research.google.com/github/OPHoperHPO/image-background-remove-tool/blob/master/docs/other/carvekit_try.ipynb\"\u003e\n\u003cimg src=\"https://camo.githubusercontent.com/52feade06f2fecbf006889a904d221e6a730c194/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667\"\u003e\u003c/a\u003e\n\n\u003c/p\u003e\n\n\n**********************************************************************\n\u003cp align=\"center\"\u003e \u003cimg align=\"center\" width=\"512\" height=\"288\" src=\"docs/imgs/compare/readme.jpg\"\u003e \u003c/p\u003e\n\n\n\u003e The higher resolution images from the picture above can be seen in the docs/imgs/compare/ and docs/imgs/input folders.\n\n#### 📙 README Language\n[Russian](docs/readme/ru.md)\n[English](README.md)\n\n## 📄 Description:  \nAutomated high-quality background removal framework for an image using neural networks.\n\n## 🎆 Features:  \n- High Quality\n- Batch Processing\n- NVIDIA CUDA and CPU processing\n- FP16 inference: Fast inference with low memory usage\n- Easy inference\n- 100% remove.bg compatible FastAPI HTTP API \n- Removes background from hairs\n- Easy integration with your code\n\n## ⛱ Try yourself on [Google Colab](https://colab.research.google.com/github/OPHoperHPO/image-background-remove-tool/blob/master/docs/other/carvekit_try.ipynb) \n## ⛓️ How does it work?\nIt can be briefly described as\n1. The user selects a picture or a folder with pictures for processing\n2. The photo is preprocessed to ensure the best quality of the output image\n3. Using machine learning technology, the background of the image is removed\n4. Image post-processing to improve the quality of the processed image\n## 🎓 Implemented Neural Networks:\n|        Networks         |                   Target                    |             Accuracy             |\n|:-----------------------:|:-------------------------------------------:|:--------------------------------:|\n| **Tracer-B7** (default) |     **General** (objects, animals, etc)     | **90%** (mean F1-Score, DUTS-TE) |\n|         U^2-net         | **Hairs** (hairs, people, animals, objects) |  80.4% (mean F1-Score, DUTS-TE)  |\n|         BASNet          |        **General** (people, objects)        |  80.3% (mean F1-Score, DUTS-TE)  |\n|        DeepLabV3        |         People, Animals, Cars, etc          |  67.4% (mean IoU, COCO val2017)  |\n\n### Recommended parameters for different models\n|  Networks   | Segmentation mask  size | Trimap parameters (dilation, erosion) |\n|:-----------:|:-----------------------:|:-------------------------------------:|\n| `tracer_b7` |           640           |                (30, 5)                |\n|   `u2net`   |           320           |                (30, 5)                |\n|  `basnet`   |           320           |                (30, 5)                |\n| `deeplabv3` |          1024           |               (40, 20)                |\n\n\u003e ### Notes: \n\u003e 1. The final quality may depend on the resolution of your image, the type of scene or object.\n\u003e 2. Use **U2-Net for hairs** and **Tracer-B7 for general images** and correct parameters. \\\n\u003e It is very important for final quality! Example images was taken by using U2-Net and FBA post-processing.\n## 🖼️ Image pre-processing and post-processing methods:\n### 🔍 Preprocessing methods:\n* `none` - No preprocessing methods used.\n\u003e They will be added in the future.\n### ✂ Post-processing methods:\n* `none` - No post-processing methods used.\n* `fba` (default) - This algorithm improves the borders of the image when removing the background from images with hair, etc. using FBA Matting neural network. This method gives the best result in combination with u2net without any preprocessing methods.\n\n## 🏷 Setup for CPU processing:\n1. `pip install carvekit --extra-index-url https://download.pytorch.org/whl/cpu`\n\u003e The project has been tested on Python versions ranging from 3.9 to 3.11.7.\n## 🏷 Setup for GPU processing:  \n1. Make sure you have an NVIDIA GPU with 8 GB VRAM.\n2. Install `CUDA Toolkit 12.1 and Video Driver for your GPU`\n3. `pip install carvekit --extra-index-url https://download.pytorch.org/whl/cu121`\n\u003e The project has been tested on Python versions ranging from 3.9 to 3.11.7.\n## 🧰 Interact via code:  \n### If you don't need deep configuration or don't want to deal with it\n``` python\nimport torch\nfrom carvekit.api.high import HiInterface\n\n# Check doc strings for more information\ninterface = HiInterface(object_type=\"hairs-like\",  # Can be \"object\" or \"hairs-like\".\n                        batch_size_seg=5,\n                        batch_size_matting=1,\n                        device='cuda' if torch.cuda.is_available() else 'cpu',\n                        seg_mask_size=640,  # Use 640 for Tracer B7 and 320 for U2Net\n                        matting_mask_size=2048,\n                        trimap_prob_threshold=231,\n                        trimap_dilation=30,\n                        trimap_erosion_iters=5,\n                        fp16=False)\nimages_without_background = interface(['./tests/data/cat.jpg'])\ncat_wo_bg = images_without_background[0]\ncat_wo_bg.save('2.png')\n\n                   \n```\n\n### If you want control everything\n``` python\nimport PIL.Image\n\nfrom carvekit.api.interface import Interface\nfrom carvekit.ml.wrap.fba_matting import FBAMatting\nfrom carvekit.ml.wrap.tracer_b7 import TracerUniversalB7\nfrom carvekit.pipelines.postprocessing import MattingMethod\nfrom carvekit.pipelines.preprocessing import PreprocessingStub\nfrom carvekit.trimap.generator import TrimapGenerator\n\n# Check doc strings for more information\nseg_net = TracerUniversalB7(device='cpu',\n              batch_size=1)\n\nfba = FBAMatting(device='cpu',\n                 input_tensor_size=2048,\n                 batch_size=1)\n\ntrimap = TrimapGenerator()\n\npreprocessing = PreprocessingStub()\n\npostprocessing = MattingMethod(matting_module=fba,\n                               trimap_generator=trimap,\n                               device='cpu')\n\ninterface = Interface(pre_pipe=preprocessing,\n                      post_pipe=postprocessing,\n                      seg_pipe=seg_net)\n\nimage = PIL.Image.open('tests/data/cat.jpg')\ncat_wo_bg = interface([image])[0]\ncat_wo_bg.save('2.png')\n                   \n```\n\n\n## 🧰 Running the CLI interface:  \n * ```python3 -m carvekit  -i \u003cinput_path\u003e -o \u003coutput_path\u003e --device \u003cdevice\u003e```  \n \n### Explanation of args:  \n````\nUsage: carvekit [OPTIONS]\n\n  Performs background removal on specified photos using console interface.\n\nOptions:\n  -i ./2.jpg                   Path to input file or dir  [required]\n  -o ./2.png                   Path to output file or dir\n  --pre none                   Preprocessing method\n  --post fba                   Postprocessing method.\n  --net tracer_b7              Segmentation Network. Check README for more info.\n  --recursive                  Enables recursive search for images in a folder\n  --batch_size 10              Batch Size for list of images to be loaded to\n                               RAM\n\n  --batch_size_seg 5           Batch size for list of images to be processed\n                               by segmentation network\n\n  --batch_size_mat 1           Batch size for list of images to be processed\n                               by matting network\n\n  --seg_mask_size 640          The size of the input image for the\n                               segmentation neural network. Use 640 for Tracer B7 and 320 for U2Net\n\n  --matting_mask_size 2048     The size of the input image for the matting\n                               neural network.\n  --trimap_dilation 30       The size of the offset radius from the\n                                  object mask in pixels when forming an\n                                  unknown area\n  --trimap_erosion 5        The number of iterations of erosion that the\n                                  object's mask will be subjected to before\n                                  forming an unknown area\n  --trimap_prob_threshold 231\n                                  Probability threshold at which the\n                                  prob_filter and prob_as_unknown_area\n                                  operations will be applied\n\n  --device cpu                 Processing Device.\n  --fp16                       Enables mixed precision processing. Use only with CUDA. CPU support is experimental!\n  --help                       Show this message and exit.\n\n\n````\n## 📦 Running the Framework / FastAPI HTTP API server via Docker:\nUsing the API via docker is a **fast** and non-complex way to have a working API.\n\u003e **Our docker images are available on [Docker Hub](https://hub.docker.com/r/anodev/carvekit).** \\\n\u003e Version tags are the same as the releases of the project with suffixes `-cpu` and `-cuda` for CPU and CUDA versions respectively.\n\n\n\u003cp align=\"center\"\u003e \n\u003cimg src=\"docs/imgs/screenshot/frontend.png\"\u003e \n\u003cimg src=\"docs/imgs/screenshot/docs_fastapi.png\"\u003e \n\u003c/p\u003e\n\n\u003e### Important Notes:\n\u003e1. Docker image has default front-end at `/` url and FastAPI backend with docs at `/docs` url.\n\u003e2. Authentication is **enabled** by default. \\\n\u003e **Token keys are reset** on every container restart if ENV variables are not set. \\\nSee `docker-compose.\u003cdevice\u003e.yml` for more information. \\\n\u003e **You can see your access keys in the docker container logs.**\n\u003e \n\u003e3. There are examples of interaction with the API.\\\n\u003e See `docs/code_examples/python` for more details\n### 🔨 Creating and running a container:\n1. Install `docker-compose`\n2. Run `docker-compose -f docker-compose.cpu.yml up -d`  # For CPU Processing\n3. Run `docker-compose -f docker-compose.cuda.yml up -d`  # For GPU Processing\n\u003e Also you can mount folders from your host machine to docker container\n\u003e and use the CLI interface inside the docker container to process \n\u003e files in this folder. \n\n\u003e Building a docker image on Windows is not officially supported. You can try using WSL2 or \"Linux Containers Mode\" but I haven't tested this.\n\n## ☑️ Testing\n\n### ☑️ Testing with local environment\n1. `pip install -r requirements_test.txt`\n2. `pytest`\n\n### ☑️ Testing with Docker\n1. Run `docker-compose -f docker-compose.cpu.yml run carvekit_api pytest`  # For testing on CPU\n2. Run `docker-compose -f docker-compose.cuda.yml run carvekit_api pytest`  # For testing on GPU\n\n## 👪 Credits: [More info](docs/CREDITS.md)\n\n## 💵 Support\n  You can thank me for developing this project and buy me a small cup of coffee ☕\n\n| Blockchain |           Cryptocurrency            |          Network          |                                             Wallet                                              |\n|:----------:|:-----------------------------------:|:-------------------------:|:-----------------------------------------------------------------------------------------------:|\n|  Ethereum  | ETH / USDT / USDC / BNB / Dogecoin  |          Mainnet          |                           0x7Ab1B8015020242D2a9bC48F09b2F34b994bc2F8                            |\n|  Ethereum  | ETH / USDT / USDC / BNB / Dogecoin  | BSC (Binance Smart Chain) |                           0x7Ab1B8015020242D2a9bC48F09b2F34b994bc2F8                            |\n|  Bitcoin   |                 BTC                 |             -             |                           bc1qmf4qedujhhvcsg8kxpg5zzc2s3jvqssmu7mmhq                            |\n|   ZCash    |                 ZEC                 |             -             |                               t1d7b9WxdboGFrcVVHG2ZuwWBgWEKhNUbtm                               |\n|    Tron    |                 TRX                 |             -             |                               TH12CADSqSTcNZPvG77GVmYKAe4nrrJB5X                                |\n|   Monero   |                 XMR                 |          Mainnet          | 48w2pDYgPtPenwqgnNneEUC9Qt1EE6eD5MucLvU3FGpY3SABudDa4ce5bT1t32oBwchysRCUimCkZVsD1HQRBbxVLF9GTh3 |\n|    TON     |                 TON                 |             -             |                        EQCznqTdfOKI3L06QX-3Q802tBL0ecSWIKfkSjU-qsoy0CWE                         |\n## 📧 __Feedback__\nI will be glad to receive feedback on the project and suggestions for integration.\n\nFor all questions write: [farvard34@gmail.com](mailto://farvard34@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fophoperhpo%2Fimage-background-remove-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fophoperhpo%2Fimage-background-remove-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fophoperhpo%2Fimage-background-remove-tool/lists"}