Recommendation task class.
tflite_model_maker.recommendation.Recommendation(
model_spec,
model_dir,
shuffle=True,
learning_rate=0.1,
gradient_clip_norm=1.0
)
Args |
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).
|
Attributes |
input_spec
|
|
model_hparams
|
|
Methods
create
View source
@classmethod
create(
train_data,
model_spec: tflite_model_maker.recommendation.ModelSpec
,
model_dir: str = None,
validation_data=None,
batch_size: int = 16,
steps_per_epoch: int = 10000,
epochs: int = 1,
learning_rate: float = 0.1,
gradient_clip_norm: float = 1.0,
shuffle: bool = True,
do_train: bool = True
)
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
create_model(
do_train=True
)
Creates a model.
Args |
do_train
|
boolean. Whether to train the model.
|
create_serving_model
View source
create_serving_model()
Returns the underlining Keras model for serving.
evaluate
View source
evaluate(
data, batch_size=10
)
Evaluate the model.
Args |
data
|
Evaluation data.
|
batch_size
|
int, batch size for evaluation.
|
Returns |
History from model.evaluate().
|
evaluate_tflite
View source
evaluate_tflite(
tflite_filepath, data
)
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
export(
export_dir,
tflite_filename='model.tflite',
label_filename='labels.txt',
vocab_filename='vocab.txt',
saved_model_filename='saved_model',
tfjs_folder_name='tfjs',
export_format=None,
**kwargs
)
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
summary()
train
View source
train(
train_data,
validation_data=None,
batch_size=16,
steps_per_epoch=100,
epochs=1
)
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().
|
Class Variables |
ALLOWED_EXPORT_FORMAT
|
(<ExportFormat.LABEL: 'LABEL'>,
<ExportFormat.TFLITE: 'TFLITE'>,
<ExportFormat.SAVED_MODEL: 'SAVED_MODEL'>)
|
DEFAULT_EXPORT_FORMAT
|
(<ExportFormat.TFLITE: 'TFLITE'>,)
|
OOV_ID
|
0
|