I have the error as "Base64 decode failed" using the following function. The following function is used to call the model that is saved in Google AI Platform. However, the data input has to be base64 serialized, hence, I include the get_serialized_example(raw) function within the tfx_test(request). Any help and advice are appreciated. Thanks in advance!
def tfx_test(request):
#User Inputs
project = request.project
model = request.model
signature = request.signature
version = request.version
#Data inputs Base64 encoder
def get_serialized_example(raw):
return tf.train.Example(
features=tf.train.Features(
feature={"value":
tf.train.Feature(bytes_list=tf.train.BytesList(value=[raw]))
}
)
).SerializeToString()
b64_country_code = base64.b64encode(get_serialized_example(request.country_code)).decode('utf-8')
b64_project_type = base64.b64encode(get_serialized_example(request.project_type)).decode('utf-8')
# ml.googleapis.com
service = googleapiclient.discovery.build('ml', 'v1')
name = 'projects/{}/models/{}'.format(project, model)
if version is not None:
name += '/versions/{}'.format(version)
response = service.projects().predict(
name=name,
body={
'signature_name': signature,
'instances': [
{
"examples":{"b64": b64_country_code[0],
"b64": b64_project_type[0]}
}]
}
).execute()
if 'error' in response:
raise RuntimeError(response['error'])
return response['predictions']