This is an app for generating a masked cutout of the most salient object in a image. Building upon the work of Ge Zheng
The API was build to take a DataURL base64 string as a post request and returns the masked image in the same format.
The code can easily be shipped to Google Cloud Run or other Docker container service.
- Download pretrained model and put them under folder "salience_model" ,(need to create folder yourself)
Since Cloud Run is stateless without access to local storage, you must bundle the model within the container. First, download/clone this repo and copy the model into the folder (the model should be in the form of the folder hierarchy /checkpoint/run1
, which is the case by default for most finetuning scripts)
Then build the image:
docker build . -t outliner
If you want to test the image locally with the same specs as Cloud Run, you can run:
docker run -p 8080:8080 --memory="2g" --cpus="1" outliner
Then, tag the image and upload it to the Google Container Registry (note, this will take awhile due to the image size!):
docker tag outliner gcr.io/[PROJECT-ID]/outliner
docker push gcr.io/[PROJECT-ID]/outliner
Once done, deploy the uploaded image to Cloud Run via the console. Set Memory Allocated to 2 GB and Maximum Requests Per Container to 1!
The Cloud Run logs will tell you how the service runs, and the INFO
log level contains Cloud Run diagnostic info, including the time it takes for a request to run.
Make a POST request to your given url with your base64 image string passed as a param 'img'