Package: removebg-infusiblecoder
removebg_infusiblecoderremovebg_infusiblecoder is a tool to remove images background.If this project has helped you, please consider making adonation.Requirementspython: >3.7, <3.11InstallationCPU support:pipinstallremovebg-infusiblecoderGPU support:pipinstallremovebg-infusiblecoder[gpu]Usage as a cliAfter the installation step you can use removebg_infusiblecoder just typingremovebg_infusiblecoderin your terminal window.Theremovebg_infusiblecodercommand has 3 subcommands, one for each input type:ifor filespfor folderssfor http serverYou can get help about the main command using:removebg_infusiblecoder --helpAs well, about all the subcommands using:removebg_infusiblecoder <COMMAND> --helpremovebg_infusiblecoderiUsed when input and output are files.Remove the background from a remote imagecurl -s http://input.png | removebg_infusiblecoder i > output.pngRemove the background from a local fileremovebg_infusiblecoder i path/to/input.png path/to/output.pngRemove the background specifying a modelremovebg_infusiblecoder -m u2netp i path/to/input.png path/to/output.pngRemove the background returning only the maskremovebg_infusiblecoder -om i path/to/input.png path/to/output.pngRemove the background applying an alpha mattingremovebg_infusiblecoder -a i path/to/input.png path/to/output.pngremovebg_infusiblecoderpUsed when input and output are folders.Remove the background from all images in a folderremovebg_infusiblecoder p path/to/input path/to/outputSame as before, but watching for new/changed files to processremovebg_infusiblecoder p -w path/to/input path/to/outputremovebg_infusiblecodersUsed to start http server.To see the complete endpoints documentation, go to:http://localhost:5000/docs.Remove the background from an image urlcurl -s "http://localhost:5000/?url=http://input.png" -o output.pngRemove the background from an uploaded imagecurl -s -F file=@/path/to/input.jpg "http://localhost:5000"  -o output.pngUsage as a libraryInput and output as bytesfromremovebg_infusiblecoderimportremoveinput_path='input.png'output_path='output.png'withopen(input_path,'rb')asi:withopen(output_path,'wb')aso:input=i.read()output=remove(input)o.write(output)Input and output as a PIL imagefromremovebg_infusiblecoderimportremovefromPILimportImageinput_path='input.png'output_path='output.png'input=Image.open(input_path)output=remove(input)output.save(output_path)Input and output as a numpy arrayfromremovebg_infusiblecoderimportremoveimportcv2input_path='input.png'output_path='output.png'input=cv2.imread(input_path)output=remove(input)cv2.imwrite(output_path,output)How to iterate over files in a performatic wayfrompathlibimportPathfromremovebg_infusiblecoderimportremove,new_sessionsession=new_session()forfileinPath('path/to/folder').glob('*.png'):input_path=str(file)output_path=str(file.parent/(file.stem+".out.png"))withopen(input_path,'rb')asi:withopen(output_path,'wb')aso:input=i.read()output=remove(input,session=session)o.write(output)Usage as a dockerJust replace theremovebg_infusiblecodercommand fordocker run syedusama5556/removebg_infusiblecoder.Try this:docker run syedusama5556/removebg_infusiblecoder i path/to/input.png path/to/output.pngModelsAll models are downloaded and saved in the user home folder in the.u2netdirectory.The available models are:modnet (download,source): A pre-trained model for general use cases modnet.isnet-general-use (download,source): A pre-trained model for general use cases isnet-general-use.u2net (download,source): A pre-trained model for general use cases.u2netp (download,source): A lightweight version of u2net model.u2net_human_seg (download,source): A pre-trained model for human segmentation.u2net_cloth_seg (download,source): A pre-trained model for Cloths Parsing from human portrait. Here clothes are parsed into 3 category: Upper body, Lower body and Full body.silueta (download,source): Same as u2net but the size is reduced to 43Mb.How to train your own modelIf You need more fine tunned models try this:https://github.com/danielgatis/rembg/issues/193#issuecomment-1055534289Some video tutorialshttps://www.youtube.com/watch?v=3xqwpXjxyMQhttps://www.youtube.com/watch?v=dFKRGXdkGJUhttps://www.youtube.com/watch?v=Ai-BS_T7yjEhttps://www.youtube.com/watch?v=dFKRGXdkGJUhttps://www.youtube.com/watch?v=D7W-C0urVcQReferenceshttps://arxiv.org/pdf/2005.09007.pdfhttps://github.com/NathanUA/U-2-Nethttps://github.com/pymatting/pymattingBuy me a coffeeLiked some of my work? Buy me a coffee (or more likely a beer)LicenseCopyright (c) 2022-presentSyed Usama AhmadLicensed underMIT License