I am a newbie with TF and deployment on GCP. SO thank you so much in advance for your help!
Currently I am trying to deploy my Mnist-handwriting flask app on Google Cloud Platform(GCP) using TensorFlow Serving. I have deployed my model on TF serving, and use a custom MySimpleScaler class to preprocess and resize image before feed it in my model. My question is that, whether there is a way to add the preprocess and resize class in my save model, so that my flask app does not have any tensorflow dependencies. The reason is that the TF library is too large for the app engine.
The flow of my app is as follow:
1) My flask app is deployed on app engine. It has a MySimpleScaler class to resize the image input from the canvas. I allow the user to draw from the canvas on the front end --> get the data using jquery --> using the parse_image function to write it as a output.jpg --> read the output.jpg from local drive and feed it to MySimpleScaler to preprocess
2) My model is deploy on AI platform using TF serving. I send a predict request using output from MysimpleScaler in step 1. The predict value is then pushed to Flask backend, and then I push it to frontend by using Jinja
Here is the two function that I use to get and preprocess data:
def parse_image(imgData):
# imgData fetch img from canvas using request.get_data()
imgstr = re.search(b"base64,(.*)", imgData).group(1)
img_decode = base64.decodebytes(imgstr)
with open("output.jpg", "wb") as file:
file.write(img_decode)
return img_decode
class MySimpleScaler(object):
def preprocess_img(self, img_decode):
# img_decode from parse_image
img_raw = img_decode
image = tf.image.decode_jpeg(img_raw, channels=1)
image = tf.image.resize(image, [28, 28])
image = (255 - image) / 255.0 # normalize to [0,1] range
image = tf.reshape(image, (1, 28, 28, 1))
return image
TL;DR: I want to add preprocess_img function as one of the layer in my save model before deploy it to the TF serving. Thank you so much for your time!