Cannot prepare a Tensorflow Decision Forests model for Earth Engine

Hi All,

I want to set up a Tensorflow decision forests model for inference using Google Earth Engine. There is already a Colab notebook example on how to do that using a Neural Network, I’m basically trying to do the same thing but with a random forest model.

However, when I try and prepare the model for “EEification” using the earth engine command line tool, it fails. I’m pretty sure the error is related to the way the earth engine command line tool calls the Tensorflow library but not sure what the solution is.

Example colab notebook with very simple example: Google Colab

The notebook requires that you have set up Earth Engine with the Google account that you authenticate with.

Thanks in advance!

Sorry for my complete ignorance on earchengine but when you call the cmd line (with the error) what happens? does it creates a VM (or container) and uses that to run the model?

My gut guess says that if it’s that, maybe that VM is missing the TFDF dependency and so lacks the missing ops.

Maybe @Mathieu or @Jan might be have some insight

No worries, I am by no means an expert either! Based upon the (not very detailed) documentation, that command prepares the model somehow. From the docs:

the Earth Engine CLI has the model prepare command that wraps an existing SavedModel in the required operations to convert input/output formats.

So I think probably all this step is doing is adding a preprocessing step to the model and saving it again as a new model. The deployment step comes later, I didn’t include it in the notebook.

Based upon the stack trace it looks like the earth engine command line tool (which is just a Python library) imports tensorflow and tries to add this preprocessing step, but fails. There are a few issues (e.g. NotFoundError when load model from different device · Issue #14 · tensorflow/decision-forests · GitHub) with similar error messages which makes me think that there are custom Tensorflow ops required that are not being imported, which causes it to fail.

Hi Matt,

For this specific issue (earth engine related) I got a suggestion to raise a questions following this: 取得協助  |  Google Earth Engine  |  Google Developers
They seem to have a process to help over there.

hope it helps

hi Matt, I’m sorry about your experience.

I can have a good guess on one of the problems: TF-DF defines what TensorFlow calls “TF Custom ops”: new algorithms (training/evaluating decision forests) implemented in c++ to be used in tensorflow.

When one does import tensorflow_decision_forests these “TF Custom Ops” get imported and it’s all fine.

Now when you run !earthengine you are likely starting another (python?) program, and likely it doesn’t import tensorflow_decision_forests, and hence cannot find the custom op :frowning:

Internally we are discussing how to provide a standard way of handling these situations: your SavedModel should somehow inform any other program what libraries (Custom Ops) it should import. But unfortunately this is not automatic yet :\ … it’s in our list of todo’s.

In the short term, this would be easier to solve by modifying earthengine to import the library.


Hi Jan, thanks for the info - I suspected it was something like that.

Looking at where the error comes from in earthengine, I can see that tensorflow_decision_forests is not imported: earthengine-api/ at a4aeed4393fd95b2769649c561f91c499c28a5de · google/earthengine-api · GitHub

I’ll try and add the import and see if it works.

earthengine is written in Python so was hoping I could just import it, however it’s designed as a command line tool and there’s no documentation on calling from Python, so sounds like it may be difficult…

Thanks for the help, will report back!

@Jan It worked! I added

import tensorflow_decision_forests here: earthengine-api/ at a4aeed4393fd95b2769649c561f91c499c28a5de · google/earthengine-api · GitHub

I guess this is an issue for the earth engine team to update he library so I’ll follow up with them.



That’s awesome @Matt.

Now, ideally this wouldn’t be necessary, but I’m happy it solved your problem in the short term!

1 Like

Just wanted to add here that actually the issue is not solved - earth engine is using Tensorflow 1 which I guess is why it’s not working with TF-DF (which I assume is not backwards compatible?) Anyway, I raised an issue here: Google Issue Tracker, so anyone interested can see progress there