Model training

class mlops.training.tensorflow.TensorFlowTrainer()

Main object for running TensorFlow jobs in MLOps.

predict(self, model)

Predicts on a trained model. In order to use this method a test dataset split must exist. The predictions are saved to your AWS account and are visible in the MLOps platform.

Arguments:

model: tf.keras.Model - the trained model

Example:

mlops = TensorFlowTrainer()
model = my_network(mlops)
model.fit(parameters)
mlops.predict(model)
read_data(self, number_of_label_cols, label_pos='end')

Read data residing on S3 into numpy arrays split into data and labels. The datasets will then be available in the mlops object as {split}_data, {split}_labels.

Arguments:

number_of_label_cols: int - the number of columns that are labels
label_pos: str - valid values are ['end', 'start'] indicating where the labels are found in the data

Example:

mlops = TensorFlowTrainer()
mlops.read_data(label_indexes=[0])
model = my_network(mlops)  # Returns a Keras model in this example
model.fit(
    mlops.train_data,
    mlops.train_labels,
    batch_size=mlops.hyperparameters["batch_size"],
    epochs=mlops.hyperparameters["epochs"],
    validation_data=(mlops.val_data, mlops.val_labels),
    callbacks=[mlops.callback],
)
save_model(self, model)

Saves the model for future use on S3. In order to be able to put the model into production at a later stage or iterate on it for further development, this stage is necessary.

Arguments:

model: tf.keras.Model - the trained model

Example:

mlops = TensorFlowTrainer()
model = my_network(mlops)
model.fit(parameters)
mlops.save(model)
class mlops.training.tensorflow.MLOpsCallback(metrics, model_id, project_id, customer_id, external_id, region, validation)

Callback method to log training metrics to MLOps. Saves data to the MLOps platform at the end of each epoch. This class should be called on training.

Example:

mlops = TensorFlowTrainer()
mlops.read_data(label_indexes=[0])
model = my_network(mlops)
model.fit(
    mlops.train_data,
    mlops.train_labels,
    batch_size=mlops.hyperparameters["batch_size"],
    epochs=mlops.hyperparameters["epochs"],
    validation_data=(mlops.val_data, mlops.val_labels),
    callbacks=[mlops.callback],
)