Using google cloud ml with Android app

2019-03-02 14:18发布

问题:

I am studying this example on google cloud ml : link. I want to know how I can connect my Android app to this so that I can send in a data value and receive the prediction back to my app after processing it through Tensorflow.

I am thinking it has to be some sort of API connection that allows us to do this but I just can't find any documentation or examples that do this.

Please help!!

回答1:

You're right, the uploaded model is then provided to you as an API and you can make normal http POST requests and obtain predictions. This is their structure.

Perhaps read a little bit about the difference between batch and online predictions. It seem you are looking for online predictions - so make sure to make requests for those, not to submit jobs.

To use this inside of an application you also need to authenticate. The easiest way to do all that is to look for the documentation of the Cloud ML Java client library.

The steps to successfully implement Cloud ML predictions in your Android app might involve:
- deploy a trained model to Cloud ML (I assume you have this)
- create a service account in the Google Cloud project, give it appropriate Cloud ML rights and download its key
- use this key from within the application to get credentials (following the API Client docs) when the application starts
- make online prediction requests

I haven't seen any super easy to follow examples on doing this end to end just yet but surely they will come at some point. Right now your best bet is probably to go through the documentation.



回答2:

Training your model using the google cloud will be much faster compared to your model training on a laptop(CPU), thus saves lot of time.But you should be able to upload a trained model to the cloud and leverage it by calling it from the Android App.