Your name: Chansung Park
Your email: [email protected]
Your company/organization: Individual(ML GDE)
Project name: FirebasePublisher
This project defines a custom TFX component to publish/update ML models to Firebase ML.
Component
This project helps users to publish trained models directly from TFX Pusher component to Firebase ML.
With Firebase ML, we can guarantee that mobile devices can be equipped with the latest ML model without explicitly embedding binary in the project compiling stage. We can even A/B test different versions of a model with Google Analytics when the model is published on Firebase ML.
Firebase ML Publisher component will be implemented as a Python class-based component. You can find the actual source code in my personal project.
The implementation details
- This component behaves similar to Pusher component, but it pushes/hosts model to Firebase ML instead. To this end, FirebasePublisher interits Pusher, and it gets the following inputs
FirebasePublisher(
display_name: str,
tags: List[str],
storage_bucket: str,
model: types.BaseChannel = None,
options: Optional[Dict] = None,
credential_path: Optional[str] = None,
model_blessing: Optional[types.BaseChannel] = None,
)
-
Each inputs:
model
: the model from the upstream TFX component such as Trainermodel_blessing
: the output ofblessing
from the Evaluator component to indicate if the givenmodel
is good enough to be pusheddisplay_name
: display name to appear in Firebase ML. This should be a unique value since it will be used to search a existing model to updatetags
: tags to appear in Firebase MLstorage_bucket
: GCS bucket where the hosted model is stored.gs://
should not be includedcredential_path
: an optional parameter, and it indicates GCS or local location where a Service Account Key (JSON) file is stored. If this parameter is not given, Application Default Credentials will be used in GCP environmentoptions
: additional configurations to be passed to initialize Firebase app
-
It outputs the following information by the method
_MarkPushed
from Pusher componentpushed
: indicator if the model is pushed without any issue or if the model is blessed.pushed_destination
: URL string for easy access to the model from Firebase Console such asf"https://console.firebase.google.com/u/1/project/{PROJECT_ID}/ml/custom"
pushed_version
: version string of the pushed model. This is determined in the same manner as Pusher bystr(int(time.time()))
-
The detailed behaviour of this component
-
Initialize Firebase App with
firebase_admin.initialize_app
from Firebase Admin SDK. Whencredential_path
is given, it first downloads the credential file and uses it in thecreds
argument of theinitialize_app()
. Whenoptions
parameter of this component is notNone
, it will be passed to theoptions
argument of theinitialize_app()
. -
Download the model from the upstream TFX component if the model is blessed. Unfortunately, Firebase ML only lets us upload/host a model from the local storage, so this step is required. Along the way, if the model is
TFLite
format, local flagis_tfile
will be marked asTrue
-
The model format can be either of
SavedModel
orTFLite
. It searches for the*.tflite
file during the downloading/copying process. When it is found,TFLiteGCSModelSource.from_tflite_model_file(model_path)
function will be used to store the model into the GCS bucket specified instorage_bucket
. If any*.tflite
is not found,TFLiteGCSModelSource.from_saved_model(model_path)
is used instead.from_saved_model()
function internally convertsSavedModel
toTFLite
, then the rest of the process is the same asfrom_tflite_model_file
. -
Search the list of models whose name is same to the
display_name
. If the list is empty, a new model will be created and hosted. If the list is non-empty, the existing modell will be updated.- In any cases, tags will be updated with the
tags
. Plus, additional tag information of the model version will be automatically added.
- In any cases, tags will be updated with the
-
The implementation will use the following libraries.
Project Leader : Chansung Park, deep-diver, [email protected]
- Sayak Paul, sayakpaul, [email protected]