tflite_model_maker.recommendation.Recommendation

Recommendation task class.

model_spec recommendation model spec.
model_dir str, path to export model checkpoints and summaries.
shuffle boolean, whether the training data should be shuffled.
learning_rate float, learning rate.
gradient_clip_norm float, clip threshold (<= 0 meaning no clip).

input_spec

model_hparams

Methods

create

View source

Loads data and train the model for recommendation.

Args
train_data Training data.
model_spec ModelSpec, Specification for the model.
model_dir str, path to export model checkpoints and summaries.
validation_data Validation data.
batch_size Batch size for training.
steps_per_epoch int, Number of step per epoch.
epochs int, Number of epochs for training.
learning_rate float, learning rate.
gradient_clip_norm float, clip threshold (<= 0 meaning no clip).
shuffle boolean, whether the training data should be shuffled.
do_train boolean, whether to run training.

Returns
An instance based on Recommendation.

create_model

View source

Creates a model.

Args
do_train boolean. Whether to train the model.

Returns
Keras model.

create_serving_model

View source

Returns the underlining Keras model for serving.

evaluate

View source

Evaluate the model.

Args
data Evaluation data.
batch_size int, batch size for evaluation.

Returns
History from model.evaluate().

evaluate_tflite

View source

Evaluates the tflite model.

The data is padded to required length, and multiple metrics are evaluated.

Args
tflite_filepath File path to the TFLite model.
data Data to be evaluated.

Returns
Dict of (metric, value), evaluation result of TFLite model.

export

View source

Converts the retrained model based on export_format.

Args
export_dir The directory to save exported files.
tflite_filename File name to save tflite model. The full export path is {export_dir}/{tflite_filename}.
label_filename File name to save labels. The full export path is {export_dir}/{label_filename}.
vocab_filename File name to save vocabulary. The full export path is {export_dir}/{vocab_filename}.
saved_model_filename Path to SavedModel or H5 file to save the model. The full export path is {export_dir}/{saved_model_filename}/{saved_model.pb|assets|variables}.
tfjs_folder_name Folder name to save tfjs model. The full export path is {export_dir}/{tfjs_folder_name}.
export_format List of export format that could be saved_model, tflite, label, vocab.
**kwargs Other parameters like quantized_config for TFLITE model.

summary

View source

train

View source

Feeds the training data for training.

Args
train_data Training dataset.
validation_data Validation data. If None, skips validation process.
batch_size int, the batch size.
steps_per_epoch int, the step of each epoch.
epochs int, number of epochs.

Returns
History from model.fit().

ALLOWED_EXPORT_FORMAT (<ExportFormat.LABEL: 'LABEL'>, <ExportFormat.TFLITE: 'TFLITE'>, <ExportFormat.SAVED_MODEL: 'SAVED_MODEL'>)
DEFAULT_EXPORT_FORMAT (<ExportFormat.TFLITE: 'TFLITE'>,)
OOV_ID 0