0

I currently have a BigQueryML model that I want to deploy in Google Earth Engine. I've exported the model to Google Cloud Storage in TensorFlow SavedModel format but am struggling to 'EEify' the model to make it a usable endpoint. The Google/Tensorflow documentation seem to be sparse regarding this, but I have found one example in a Colab notebook that helps but doesn't go into enough detail:

from tensorflow.python.tools import saved_model_utils

meta_graph_def = saved_model_utils.get_meta_graph_def('gs://...', 'serve')
inputs = meta_graph_def.signature_def['serving_default'].inputs
outputs = meta_graph_def.signature_def['serving_default'].outputs

I can't seem to find any documentation regarding saved_model_utils and when I execute this chunk of code with my model path, inputs and outputs both return as an empty array.

# Just get the first thing(s) from the serving signature def.  i.e. this
# model only has a single input and a single output.
input_name = None
for k,v in inputs.items():
  input_name = v.name
  break

output_name = None
for k,v in outputs.items():
  output_name = v.name
  break

# Make a dictionary that maps Earth Engine outputs and inputs to
# AI Platform inputs and outputs, respectively.
import json
input_dict = "'" + json.dumps({input_name: "array"}) + "'"
output_dict = "'" + json.dumps({output_name: "output"}) + "'"
print(input_dict)
print(output_dict)

Due to the first chunk not working, this chunk only results in another empty array.

# Put the EEified model next to the trained model directory.
EEIFIED_DIR = 'gs://' + OUTPUT_BUCKET + '/eeified_pixel_model'

# You need to set the project before using the model prepare command.
!earthengine set_project {PROJECT}
!earthengine model prepare --source_dir {MODEL_DIR} --dest_dir {EEIFIED_DIR} --input {input_dict} --output {output_dict}

If I understand correctly, isn't the input dict just a mapping of the model's inputs (the bands of a GEE Image) towards a Tensorflow input? And the output would be a similar mapping? In which case, it seems feasible to just do this manually, but I can't find enough documentation supporting this.

Thanks

Brandon Barry
  • 61
  • 1
  • 6

0 Answers0