This sample script shows how you can use the Firebase Admin SDK to manage your Firebase-hosted ML models.
Also see the Firebase ML API Tutorial Colab/Jupyter notebook.
-
Install the Admin SDK (probably in a virtual environment):
$ pip install -U pip setuptools $ pip install firebase_admin -
Clone the quickstart repository and change to the
machine-learningdirectory:$ git clone https://github.com/firebase/quickstart-python.git $ cd quickstart-python/machine-learning $ chmod u+x manage-ml.py # Optional -
If you don't already have a Firebase project, create a new project in the Firebase console. Then, open your project in the Firebase console and do the following:
- On the Settings page, create a service account and download the service account key file. Keep this file safe, since it grants administrator access to your project.
- On the Storage page, enable Cloud Storage. Take note of your default bucket name (or create a new bucket for ML models.)
- On the ML Kit page, click Get started if you haven't yet enabled ML Kit.
-
In the Google APIs console, open your Firebase project and enable the Firebase ML API.
-
At the top of
manage-ml.py, set theSERVICE_ACCOUNT_KEYandSTORAGE_BUCKET:SERVICE_ACCOUNT_KEY = '/path/to/your/service_account_key.json' STORAGE_BUCKET = 'your-storage-bucket'
$ ./manage-ml.py list
fish_detector 8716935 vision
barcode_scanner 8716959 vision
smart_reply 8716981 natural_language
$ ./manage-ml.py new ~/yak.tflite yak_detector --tags vision,experimental
Uploading model to Cloud Storage...
Model uploaded and published:
yak_detector 8717019 experimental, vision
$ ./manage-ml.py update 8717019 --remove_tags experimental
$ ./manage-ml.py delete 8716959
$ ./manage-ml.py list
fish_detector 8716935 vision
smart_reply 8716981 natural_language
yak_detector 8717019 vision
$