Fast APi of pretrained model

Hi all,

What is the easiest way to use the pretrained model of ade20k Xception in python?
I’m a programmer but just not a python programmer. I managed to use the pretrained Deeplab model in javascript. But I suppose the Xception model is in Python is better trained? I would host this as a web api using Fast API or Flask. The API should accept a link to a image. Run the detection and sends back the result image (with all the colors).

Kind regards.
Roel

Hello @Roel_Van_der_planken

Thank you for using TensorFlow,
Initially, you have to setup Flask server, and should be given a option to load model, an API endpoint should be created so that it accepts POST requests.
Here is the pseudo code,

FUNCTION preprocess_image
Convert image to RGB format and change it to tensor
RETURN input_tensor

FUNCTION colorize_segmentation_map
Convert tensor to map ID’s, Create a new blank color image array, and assign colors to different segments, Convert the final colored array back to an image object
RETURN colored_image_object

For API Endpoints

DEFINE_ROUTE(APP, path=“/segment/”, methods=[“POST”])
PROCEDURE handle_segmentation_request(request):
input_tensor = preprocess_image
prediction_output = AI_MODEL.predict(input_tensor)
Get prediction and Extract the primary segmentation map, Convert the map to a colored image
Send the PNG image back as the response
RETURN FileResponse(png_bytes, mimetype=“image/png”)

DEFINE_ROUTE(APP, path=“/”, methods=[“GET”])
PROCEDURE handle_root_request(request):
RETURN TextResponse(“Segmentation API is active. POST to /segment/”)
END PROCEDURE
END DEFINE_ROUTE
Server Execution
PRINT “Starting web server…”
START_WEB_SERVER(APP, host=“0.0.0.0”, port=8000)

Try to follow this pseudo code to get your hands on building and serving Flask app and try to catch errors, wherever you are trying to get requests from any URL.

Thank you