8000 Deprecating the feature to publish from an AutoML Model · firebase/firebase-admin-python@1c6571b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c6571b

Browse files
committed
Deprecating the feature to publish from an AutoML Model
1 parent b9e95e8 commit 1c6571b

File tree

3 files changed

+0
-157
lines changed

3 files changed

+0
-157
lines changed

firebase_admin/ml.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,6 @@ def _init_model_source(data):
386386
gcs_tflite_uri = data.pop('gcsTfliteUri', None)
387387
if gcs_tflite_uri:
388388
return TFLiteGCSModelSource(gcs_tflite_uri=gcs_tflite_uri)
389-
auto_ml_model = data.pop('automlModel', None)
390-
if auto_ml_model:
391-
return TFLiteAutoMlSource(auto_ml_model=auto_ml_model)
392389
return None
393390

394391
@property
@@ -603,36 +600,6 @@ def as_dict(self, for_upload=False):
603600
return {'gcsTfliteUri': self._gcs_tflite_uri}
604601

605602

606< 8000 code>-
class TFLiteAutoMlSource(TFLiteModelSource):
607-
"""TFLite model source representing a tflite model created with AutoML."""
608-
609-
def __init__(self, auto_ml_model, app=None):
610-
self._app = app
611-
self.auto_ml_model = auto_ml_model
612-
613-
def __eq__(self, other):
614-
if isinstance(other, self.__class__):
615-
return self.auto_ml_model == other.auto_ml_model
616-
return False
617-
618-
def __ne__(self, other):
619-
return not self.__eq__(other)
620-
621-
@property
622-
def auto_ml_model(self):
623-
"""Resource name of the model, created by the AutoML API or Cloud console."""
624-
return self._auto_ml_model
625-
626-
@auto_ml_model.setter
627-
def auto_ml_model(self, auto_ml_model):
628-
self._auto_ml_model = _validate_auto_ml_model(auto_ml_model)
629-
630-
def as_dict(self, for_upload=False):
631-
"""Returns a serializable representation of the object."""
632-
# Upload is irrelevant for auto_ml models
633-
return {'automlModel': self._auto_ml_model}
634-
635-
636603
class ListModelsPage:
637604
"""Represents a page of models in a Firebase project.
638605

integration/test_ml.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
except ImportError:
3636
_TF_ENABLED = False
3737

38-
try:
39-
from google.cloud import automl_v1
40-
_AUTOML_ENABLED = True
41-
except ImportError:
42-
_AUTOML_ENABLED = False
43-
4438
def _random_identifier(prefix):
4539
#pylint: disable=unused-variable
4640
suffix = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(8)])
@@ -159,14 +153,6 @@ def check_tflite_gcs_format(model, validation_error=None):
159153
assert model.model_hash is not None
160154

161155

162-
def check_tflite_automl_format(model):
163-
assert model.validation_error is None
164-
assert model.published is False
165-
assert model.model_format.model_source.auto_ml_model.startswith('projects/')
166-
# Automl models don't have validation errors since they are references
167-
# to valid automl models.
168-
169-
170156
@pytest.mark.parametrize('firebase_model', [NAME_AND_TAGS_ARGS], indirect=True)
171157
def test_create_simple_model(firebase_model):
172158
check_model(firebase_model, NAME_AND_TAGS_ARGS)
@@ -388,50 +374,3 @@ def test_from_saved_model(saved_model_dir):
388374
assert created_model.validation_error is None
389375
finally:
390376
_clean_up_model(created_model)
391-
392-
393-
# Test AutoML functionality if AutoML is enabled.
394-
#'pip install google-cloud-automl' in the environment if you want _AUTOML_ENABLED = True
395-
# You will also need a predefined AutoML model named 'admin_sdk_integ_test1' to run the
396-
# successful test. (Test is skipped otherwise)
397-
398-
@pytest.fixture
399-
def automl_model():
400-
assert _AUTOML_ENABLED
401-
402-
# It takes > 20 minutes to train a model, so we expect a predefined AutoMl
403-
# model named 'admin_sdk_integ_test1' to exist in the project, or we skip
404-
# the test.
405-
automl_client = automl_v1.AutoMlClient()
406-
project_id = firebase_admin.get_app().project_id
407-
parent = automl_client.location_path(project_id, 'us-central1')
408-
models = automl_client.list_models(parent, filter_="display_name=admin_sdk_integ_test1")
409-
# Expecting exactly one. (Ok to use last one if somehow more than 1)
410-
automl_ref = None
411-
for model in models:
412-
automl_ref = model.name
413-
414-
# Skip if no pre-defined model. (It takes min > 20 minutes to train a model)
415-
if automl_ref is None:
416-
pytest.skip("No pre-existing AutoML model found. Skipping test")
417-
418-
source = ml.TFLiteAutoMlSource(automl_ref)
419-
tflite_format = ml.TFLiteFormat(model_source=source)
420-
ml_model = ml.Model(
421-
display_name=_random_identifier('TestModel_automl_'),
422-
tags=['test_automl'],
423-
model_format=tflite_format)
424-
model = ml.create_model(model=ml_model)
425-
yield model
426-
_clean_up_model(model)
427-
428-
@pytest.mark.skipif(not _AUTOML_ENABLED, reason='AutoML is required for this test.')
429-
def test_automl_model(automl_model):
430-
# This test looks for a predefined automl model with display_name = 'admin_sdk_integ_test1'
431-
automl_model.wait_for_unlocked()
432-
433-
check_model(automl_model, {
434-
'display_name': automl_model.display_name,
435-
'tags': ['test_automl'],
436-
})
437-
check_tflite_automl_format(automl_model)

tests/test_ml.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,6 @@
122122
}
123123
TFLITE_FORMAT_2 = ml.TFLiteFormat.from_dict(TFLITE_FORMAT_JSON_2)
124124

125-
AUTOML_MODEL_NAME = 'projects/111111111111/locations/us-central1/models/ICN7683346839371803263'
126-
AUTOML_MODEL_SOURCE = ml.TFLiteAutoMlSource(AUTOML_MODEL_NAME)
127-
TFLITE_FORMAT_JSON_3 = {
128-
'automlModel': AUTOML_MODEL_NAME,
129-
'sizeBytes': '3456789'
130-
}
131-
TFLITE_FORMAT_3 = ml.TFLiteFormat.from_dict(TFLITE_FORMAT_JSON_3)
132-
133-
AUTOML_MODEL_NAME_2 = 'projects/2222222222/locations/us-central1/models/ICN2222222222222222222'
134-
AUTOML_MODEL_NAME_JSON_2 = {'automlModel': AUTOML_MODEL_NAME_2}
135-
AUTOML_MODEL_SOURCE_2 = ml.TFLiteAutoMlSource(AUTOML_MODEL_NAME_2)
136-
137125
CREATED_UPDATED_MODEL_JSON_1 = {
138126
'name': MODEL_NAME_1,
139127
'displayName': DISPLAY_NAME_1,
@@ -417,14 +405,6 @@ def test_model_keyword_based_creation_and_setters(self):
417405
'tfliteModel': TFLITE_FORMAT_JSON_2
418406
}
419407

420-
model.model_format = TFLITE_FORMAT_3
421-
assert model.as_dict() == {
422-
'displayName': DISPLAY_NAME_2,
423-
'tags': TAGS_2,
424-
'tfliteModel': TFLITE_FORMAT_JSON_3
425-
}
426-
427-
428408
def test_gcs_tflite_model_format_source_creation(self):
429409
model_source = ml.TFLiteGCSModelSource(gcs_tflite_uri=GCS_TFLITE_URI)
430410
model_format = ml.TFLiteFormat(model_source=model_source)
@@ -436,17 +416,6 @@ def test_gcs_tflite_model_format_source_creation(self):
436416
}
437417
}
438418

439-
def test_auto_ml_tflite_model_format_source_creation(self):
440-
model_source = ml.TFLiteAutoMlSource(auto_ml_model=AUTOML_MODEL_NAME)
441-
model_format = ml.TFLiteFormat(model_source=model_source)
442-
model = ml.Model(display_name=DISPLAY_NAME_1, model_format=model_format)
443-
assert model.as_dict() == {
444-
'displayName': DISPLAY_NAME_1,
445-
'tfliteModel': {
446-
'automlModel': AUTOML_MODEL_NAME
447-
}
448-
}
449-
450419
def test_source_creation_from_tflite_file(self):
451420
model_source = ml.TFLiteGCSModelSource.from_tflite_model_file(
452421
"my_model.tflite", "my_bucket")
@@ -460,13 +429,6 @@ def test_gcs_tflite_model_source_setters(self):
460429
assert model_source.gcs_tflite_uri == GCS_TFLITE_URI_2
461430
assert model_source.as_dict() == GCS_TFLITE_URI_JSON_2
462431

463-
def test_auto_ml_tflite_model_source_setters(self):
464-
model_source = ml.TFLiteAutoMlSource(AUTOML_MODEL_NAME)
465-
model_source.auto_ml_model = AUTOML_MODEL_NAME_2
466-
assert model_source.auto_ml_model == AUTOML_MODEL_NAME_2
467-
assert model_source.as_dict() == AUTOML_MODEL_NAME_JSON_2
468-
469-
470432
def test_model_format_setters(self):
471433
model_format = ml.TFLiteFormat(model_source=GCS_TFLITE_MODEL_SOURCE)
472434
model_format.model_source = GCS_TFLITE_MODEL_SOURCE_2
@@ -477,14 +439,6 @@ def test_model_format_setters(self):
477439
}
478440
}
479441

480-
model_format.model_source = AUTOML_MODEL_SOURCE
481-
assert model_format.model_source == AUTOML_MODEL_SOURCE
482-
assert model_format.as_dict() == {
483-
'tfliteModel': {
484-
'automlModel': AUTOML_MODEL_NAME
485-
}
486-
}
487-
488442
def test_model_as_dict_for_upload(self):
489443
model_source = ml.TFLiteGCSModelSource(gcs_tflite_uri=GCS_TFLITE_URI)
490444
model_format = ml.TFLiteFormat(model_source=model_source)
@@ -570,23 +524,6 @@ def test_gcs_tflite_source_validation_errors(self, uri, exc_type):
570524
ml.TFLiteGCSModelSource(gcs_tflite_uri=uri)
571525
check_error(excinfo, exc_type)
572526

573-
@pytest.mark.parametrize('auto_ml_model, exc_type', [
574-
(123, TypeError),
575-
('abc', ValueError),
576-
('/projects/123456/locations/us-central1/models/noLeadingSlash', ValueError),
577-
('projects/123546/models/ICN123456', ValueError),
578-
('projects//locations/us-central1/models/ICN123456', ValueError),
579-
('projects/123456/locations//models/ICN123456', ValueError),
580-
('projects/123456/locations/us-central1/models/', ValueError),
581-
('projects/ABC/locations/us-central1/models/ICN123456', ValueError),
582-
('projects/123456/locations/us-central1/models/@#$%^&', ValueError),
583-
('projects/123456/locations/us-cent/ral1/models/ICN123456', ValueError),
584-
])
585-
def test_auto_ml_tflite_source_validation_errors(self, auto_ml_model, exc_type):
586-
with pytest.raises(exc_type) as excinfo:
587-
ml.TFLiteAutoMlSource(auto_ml_model=auto_ml_model)
588-
check_error(excinfo, exc_type)
589-
590527
def test_wait_for_unlocked_not_locked(self):
591528
model = ml.Model(display_name="not_locked")
592529
model.wait_for_unlocked()

0 commit comments

Comments
 (0)
0