-
Couldn't load subscription status.
- Fork 344
added support for automl-models #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -52,6 +52,9 @@ | |||||
| _TAG_PATTERN = re.compile(r'^[A-Za-z0-9_-]{1,60}$') | ||||||
| _GCS_TFLITE_URI_PATTERN = re.compile( | ||||||
| r'^gs://(?P<bucket_name>[a-z0-9_.-]{3,63})/(?P<blob_name>.+)$') | ||||||
| _AUTO_ML_MODEL_PATTERN = re.compile( | ||||||
| r'^projects/(?P<project_id>[a-z0-9-]{6,30})/locations/(?P<location_id>[^/]+)/' + | ||||||
| r'models/(?P<model_id>[A-Za-z0-9]+)$') | ||||||
| _RESOURCE_NAME_PATTERN = re.compile( | ||||||
| r'^projects/(?P<project_id>[a-z0-9-]{6,30})/models/(?P<model_id>[A-Za-z0-9_-]{1,60})$') | ||||||
| _OPERATION_NAME_PATTERN = re.compile( | ||||||
|
|
@@ -362,15 +365,10 @@ def __init__(self, model_source=None): | |||||
| def from_dict(cls, data): | ||||||
| """Create an instance of the object from a dict.""" | ||||||
| data_copy = dict(data) | ||||||
| model_source = None | ||||||
| gcs_tflite_uri = data_copy.pop('gcsTfliteUri', None) | ||||||
| if gcs_tflite_uri: | ||||||
| model_source = TFLiteGCSModelSource(gcs_tflite_uri=gcs_tflite_uri) | ||||||
| tflite_format = TFLiteFormat(model_source=model_source) | ||||||
| tflite_format = TFLiteFormat(model_source=cls._init_model_source(data_copy)) | ||||||
| tflite_format._data = data_copy # pylint: disable=protected-access | ||||||
| return tflite_format | ||||||
|
|
||||||
|
|
||||||
| def __eq__(self, other): | ||||||
| if isinstance(other, self.__class__): | ||||||
| # pylint: disable=protected-access | ||||||
|
|
@@ -380,6 +378,17 @@ def __eq__(self, other): | |||||
| def __ne__(self, other): | ||||||
| return not self.__eq__(other) | ||||||
|
|
||||||
| @staticmethod | ||||||
| def _init_model_source(data): | ||||||
| model_source = None | ||||||
| gcs_tflite_uri = data.pop('gcsTfliteUri', None) | ||||||
| if gcs_tflite_uri: | ||||||
| model_source = TFLiteGCSModelSource(gcs_tflite_uri=gcs_tflite_uri) | ||||||
| auto_ml_model = data.pop('automlModel', None) | ||||||
| if auto_ml_model: | ||||||
| model_source = TFLiteAutoMlSource(auto_ml_model=auto_ml_model) | ||||||
|
||||||
| return model_source | ||||||
|
|
||||||
| @property | ||||||
| def model_source(self): | ||||||
| """The TF Lite model's location.""" | ||||||
|
|
@@ -592,6 +601,36 @@ def as_dict(self, for_upload=False): | |||||
| return {'gcsTfliteUri': self._gcs_tflite_uri} | ||||||
|
|
||||||
|
|
||||||
| class TFLiteAutoMlSource(TFLiteModelSource): | ||||||
| """TFLite model source representing a tflite model created via AutoML.""" | ||||||
|
|
||||||
| def __init__(self, auto_ml_model, app=None): | ||||||
| self._app = app | ||||||
| self.auto_ml_model = auto_ml_model | ||||||
|
|
||||||
| def __eq__(self, other): | ||||||
| if isinstance(other, self.__class__): | ||||||
| return self._auto_ml_model == other.auto_ml_model | ||||||
|
||||||
| return self._auto_ml_model == other.auto_ml_model | |
| return self.auto_ml_model == other.auto_ml_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done