@@ -196,6 +196,7 @@ def __init__(self, display_name=None, tags=None, model_format=None):
196
196
197
197
@classmethod
198
198
def from_dict (cls , data , app = None ):
199
+ """Create an instance of the object from a dict."""
199
200
data_copy = dict (data )
200
201
tflite_format = None
201
202
tflite_format_data = data_copy .pop ('tfliteModel' , None )
@@ -223,13 +224,16 @@ def __ne__(self, other):
223
224
224
225
@property
225
226
def model_id (self ):
227
+ """The model's ID, unique to the project."""
226
228
if not self ._data .get ('name' ):
227
229
return None
228
230
_ , model_id = _validate_and_parse_name (self ._data .get ('name' ))
229
231
return model_id
230
232
231
233
@property
232
234
def display_name (self ):
235
+ """The model's display name, used to refer to the model in code and in
236
+ the Firebase console."""
233
237
return self ._data .get ('displayName' )
234
238
235
239
@display_name .setter
@@ -239,7 +243,7 @@ def display_name(self, display_name):
239
243
240
244
@property
241
245
def create_time (self ):
242
- """Returns the creation timestamp """
246
+ """The time the model was created. """
243
247
seconds = self ._data .get ('createTime' , {}).get ('seconds' )
244
248
if not isinstance (seconds , numbers .Number ):
245
249
return None
@@ -248,7 +252,7 @@ def create_time(self):
248
252
249
253
@property
250
254
def update_time (self ):
251
- """Returns the last update timestamp """
255
+ """The time the model was last updated. """
252
256
seconds = self ._data .get ('updateTime' , {}).get ('seconds' )
253
257
if not isinstance (seconds , numbers .Number ):
254
258
return None
@@ -257,22 +261,28 @@ def update_time(self):
257
261
258
262
@property
259
263
def validation_error (self ):
264
+ """Validation error message."""
260
265
return self ._data .get ('state' , {}).get ('validationError' , {}).get ('message' )
261
266
262
267
@property
263
268
def published (self ):
269
+ """True if the model is published and available for clients to
270
+ download."""
264
271
return bool (self ._data .get ('state' , {}).get ('published' ))
265
272
266
273
@property
267
274
def etag (self ):
275
+ """The entity tag (ETag) of the model resource."""
268
276
return self ._data .get ('etag' )
269
277
270
278
@property
271
279
def model_hash (self ):
280
+ """SHA256 hash of the model binary."""
272
281
return self ._data .get ('modelHash' )
273
282
274
283
@property
275
284
def tags (self ):
285
+ """Tag strings, used for filtering query results."""
276
286
return self ._data .get ('tags' )
277
287
278
288
@tags .setter
@@ -282,6 +292,7 @@ def tags(self, tags):
282
292
283
293
@property
284
294
def locked (self ):
295
+ """True if the Model object is locked by an active operation."""
285
296
return bool (self ._data .get ('activeOperations' ) and
286
297
len (self ._data .get ('activeOperations' )) > 0 )
287
298
@@ -307,6 +318,8 @@ def wait_for_unlocked(self, max_time_seconds=None):
307
318
308
319
@property
309
320
def model_format (self ):
321
+ """The model's ``ModelFormat`` object, which represents the model's
322
+ format and storage location."""
310
323
return self ._model_format
311
324
312
325
@model_format .setter
@@ -317,6 +330,7 @@ def model_format(self, model_format):
317
330
return self
318
331
319
332
def as_dict (self , for_upload = False ):
333
+ """Returns a serializable representation of the object."""
320
334
copy = dict (self ._data )
321
335
if self ._model_format :
322
336
copy .update (self ._model_format .as_dict (for_upload = for_upload ))
@@ -326,6 +340,7 @@ def as_dict(self, for_upload=False):
326
340
class ModelFormat (object ):
327
341
"""Abstract base class representing a Model Format such as TFLite."""
328
342
def as_dict (self , for_upload = False ):
343
+ """Returns a serializable representation of the object."""
329
344
raise NotImplementedError
330
345
331
346
@@ -344,6 +359,7 @@ def __init__(self, model_source=None):
344
359
345
360
@classmethod
346
361
def from_dict (cls , data ):
362
+ """Create an instance of the object from a dict."""
347
363
data_copy = dict (data )
348
364
model_source = None
349
365
gcs_tflite_uri = data_copy .pop ('gcsTfliteUri' , None )
@@ -366,6 +382,7 @@ def __ne__(self, other):
366
382
367
383
@property
368
384
def model_source (self ):
385
+ """The TF Lite model's location."""
369
386
return self ._model_source
370
387
371
388
@model_source .setter
@@ -377,9 +394,11 @@ def model_source(self, model_source):
377
394
378
395
@property
379
396
def size_bytes (self ):
397
+ """The size in bytes of the TF Lite model."""
380
398
return self ._data .get ('sizeBytes' )
381
399
382
400
def as_dict (self , for_upload = False ):
401
+ """Returns a serializable representation of the object."""
383
402
copy = dict (self ._data )
384
403
if self ._model_source :
385
404
copy .update (self ._model_source .as_dict (for_upload = for_upload ))
@@ -389,6 +408,7 @@ def as_dict(self, for_upload=False):
389
408
class TFLiteModelSource (object ):
390
409
"""Abstract base class representing a model source for TFLite format models."""
391
410
def as_dict (self , for_upload = False ):
411
+ """Returns a serializable representation of the object."""
392
412
raise NotImplementedError
393
413
394
414
@@ -415,6 +435,7 @@ def _parse_gcs_tflite_uri(uri):
415
435
416
436
@staticmethod
417
437
def upload (bucket_name , model_file_name , app ):
438
+ """Upload a model file to the specified Storage bucket."""
418
439
_CloudStorageClient ._assert_gcs_enabled ()
419
440
bucket = storage .bucket (bucket_name , app = app )
420
441
blob_name = _CloudStorageClient .BLOB_NAME .format (model_file_name )
@@ -531,6 +552,7 @@ def from_keras_model(cls, keras_model, bucket_name=None, app=None):
531
552
532
553
@property
533
554
def gcs_tflite_uri (self ):
555
+ """URI of the model file in Cloud Storage."""
534
556
return self ._gcs_tflite_uri
535
557
536
558
@gcs_tflite_uri .setter
@@ -542,6 +564,7 @@ def _get_signed_gcs_tflite_uri(self):
542
564
return TFLiteGCSModelSource ._STORAGE_CLIENT .sign_uri (self ._gcs_tflite_uri , self ._app )
543
565
544
566
def as_dict (self , for_upload = False ):
567
+ """Returns a serializable representation of the object."""
545
568
if for_upload :
546
569
return {'gcsTfliteUri' : self ._get_signed_gcs_tflite_uri ()}
547
570
@@ -578,11 +601,12 @@ def list_filter(self):
578
601
579
602
@property
580
603
def next_page_token (self ):
604
+ """Token identifying the next page of results."""
581
605
return self ._list_response .get ('nextPageToken' , '' )
582
606
583
607
@property
584
608
def has_next_page (self ):
585
- """A boolean indicating whether more pages are available."""
609
+ """True if more pages are available."""
586
610
return bool (self .next_page_token )
587
611
588
612
def get_next_page (self ):
0 commit comments