Pixellib - removing background takes huge processing

Viewed 685

I am using Pixellib library in Python to detect a person and change its background, as shown in their example here.

It works flawlessly, but takes huge processing power on my laptop, coupled with their large (~150mb) pascalvoc model, thus rendering an image in approx 4-5sec.

I need to be able to do the same via a mobile phone app, so certainly this cannot be run on a user's mobile. Alternative is to run this on cloud and return the processed image back. This is both costly if user requests increase and will still have noticable lag on user's app.

So, how do achieve this? Apps like Canva Pro seem to do this seamlessly in an app fairly quickly. In fact, there are many other 'free' apps on Play store claiming to do the same.

Thus, is there a better way to run Pixellib, to make it more performant? Or any other library that can provide similar (or better) ouptut and can be run on user's mobile?

1 Answers

There is remove.bg
It is the most easy tool,to remove background automatically
Sample code:-https://www.remove.bg/api#sample-code
Screenshots: Picture picture2 Here is an example of doing in Python:

# Requires "requests" to be installed (see python-requests.org)
import requests

response = requests.post(
'https://api.remove.bg/v1.0/removebg',
files={'image_file': open('/path/to/file.jpg', 'rb')},
data={'size': 'auto'},
headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'},
)
if response.status_code == requests.codes.ok:
    with open('no-bg.png', 'wb') as out:
        out.write(response.content)
else:
    print("Error:", response.status_code, response.text)

Since your are using python , This https://github.com/brilam/remove-bg by @brilam will help you.
It is a Python API wrapper for removing backgrounds from picture using remove.bg's API. But it also offers go based command line tool:-https://github.com/remove-bg/go


In addition to that, there are many other opensource library for python in GitHub for your reference:
https://github.com/topics/background-removal?l=python

Also, you can try,
https://github.com/danielgatis/rembg

OR, refer research paper for your understanding: https://arxiv.org/pdf/2005.09007.pdf

Related