Android - Calling a Google Cloud (AI Platfrorm)Deployed Tensorflow Model
****under development*******
RESOURCES for Credential setup (STEP 2)
RESOURCES for Android AI Model Invocation:
- OPTION 1: REST request from Java https://cloud.google.com/ml-engine/docs/online-predict (online prediction is setup to be faster/lower latency than batch predictions --meant for a "runtime scenario")
MORE: https://cloud.google.com/ml-engine/reference/rest/
- OPTON 2: ML Engine wrapper for older version of API https://github.com/googlesamples/android-TensorFlowCloudMachineLearningEngineStylizer
RESOURCES for setting up data portion of request
https://cloud.google.com/ml-engine/docs/v1/predict-request
Step 1: assumes you have already created a model and deployed it on Google's Cloud AI Platform (see here for steps)
Step 2: create credentials
Allowing Android Apps to Access Google Cloud API Services
Step 2.1) Create a new service account (https://cloud.google.com/iam/docs/creating-managing-service-accounts#iam-service-accounts-create-console)
>>https://cloud.google.com/ml-engine/docs/access-control --
For the role of the service account choose
AI Platform Developer |
Create training and prediction jobs, models and versions, and send online prediction requests. |


Step 2.3) Create a secret key (.JSON file) and store it locally
This is what the json file looks like (with some information hidden for security) - it has private_key_id, private_key etc.
NOW you can see that the service account has a key associated with it
Step 3: Setup Android Code so that it uses the key information to make requests to deployed Google Cloud Model
-
step 3.1 create api credentials
Step4. Clone the Github repository at this URL for the next steps: https://github.com/googlesamples/android-TensorFlowCloudMachineLearningEngineStylizer)
5. Update Gradle file to make it de-bugable and swap ‘implementation’ for ‘compile’ in the
Gradle dependencies to get rid of error messages (dependencies are a bit outdated, but
still appear to be working).
6. Create a ‘raw’ folder in the res directory of the project and copy the secret key created in
step 3 into it.
7. Open the CMLEHandler class file, comment out the lines to get the secret key file
inputstream, and add the single line of code to get the jsonCredentials inputstream (see
image below).
8. Test app in debug mode to verify that you can connect with the secret key.
9.
WHY is the cloud so slow? --by default: they serve it on a "low end" cpu only machine (really?)