Saving signatures and input example in train_mlflow.py
This commit is contained in:
parent
d64fd7a7dc
commit
5f107e11fb
@ -34,8 +34,8 @@ pipeline {
|
|||||||
sh 'chmod +x dlgssdpytorch.py'
|
sh 'chmod +x dlgssdpytorch.py'
|
||||||
sh 'python3 ./dlgssdpytorch.py $PARAMETRY'
|
sh 'python3 ./dlgssdpytorch.py $PARAMETRY'
|
||||||
sh 'chmod +x train_mlflow.py'
|
sh 'chmod +x train_mlflow.py'
|
||||||
sh 'chmod +x generate_MLmodel.py'
|
//sh 'chmod +x generate_MLmodel.py'
|
||||||
sh 'python3 ./generate_MLmodel.py'
|
//sh 'python3 ./generate_MLmodel.py'
|
||||||
//sh 'mlflow ./train_mlflow.py'
|
//sh 'mlflow ./train_mlflow.py'
|
||||||
//sh 'mlflow run .'
|
//sh 'mlflow run .'
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import argparse
|
|||||||
import mlflow
|
import mlflow
|
||||||
import mlflow.pytorch
|
import mlflow.pytorch
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
from mlflow.models.signature import infer_signature
|
||||||
|
|
||||||
|
|
||||||
class LayerLinearRegression(nn.Module):
|
class LayerLinearRegression(nn.Module):
|
||||||
@ -28,6 +29,7 @@ args = parser.parse_args()
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
lr = args.lr
|
lr = args.lr
|
||||||
n_epochs = args.epochs
|
n_epochs = args.epochs
|
||||||
|
mlflow.set_experiment("s426206")
|
||||||
with mlflow.start_run():
|
with mlflow.start_run():
|
||||||
mlflow.log_param("lr", lr)
|
mlflow.log_param("lr", lr)
|
||||||
mlflow.log_param("epochs", n_epochs)
|
mlflow.log_param("epochs", n_epochs)
|
||||||
@ -119,15 +121,19 @@ if __name__ == "__main__":
|
|||||||
'loss': lr,
|
'loss': lr,
|
||||||
}, 'model.pt')
|
}, 'model.pt')
|
||||||
|
|
||||||
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
|
x_train = np.array(train_dataset)[:,0] #(Sales Sum row)
|
||||||
|
input_example = np.reshape(x_train, (-1,1))
|
||||||
|
|
||||||
|
with torch.no_grad():
|
||||||
|
model.eval()
|
||||||
|
siganture = infer_signature(x_train, model(torch.tensor(np.reshape(x_train, (-1,1))).float()).numpy())
|
||||||
|
|
||||||
|
#mlflow.set_experiment("s426206")
|
||||||
|
#mlflow.set_tracking_uri("http://172.17.0.1:5000")
|
||||||
|
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
|
||||||
|
# print(tracking_url_type_store)
|
||||||
# Model registry does not work with file store
|
# Model registry does not work with file store
|
||||||
if tracking_url_type_store != "file":
|
if tracking_url_type_store != "file":
|
||||||
|
mlflow.sklearn.log_model(model, "model", registered_model_name="s426206", signature=siganture, input_example=input_example)
|
||||||
# Register the model
|
|
||||||
# There are other ways to use the Model Registry, which depends on the use case,
|
|
||||||
# please refer to the doc for more information:
|
|
||||||
# https://mlflow.org/docs/latest/model-registry.html#api-workflow
|
|
||||||
mlflow.sklearn.log_model(model, "model", registered_model_name="ElasticnetWineModel")
|
|
||||||
else:
|
else:
|
||||||
mlflow.sklearn.log_model(model, "model")
|
mlflow.sklearn.log_model(model, "model", signature=siganture, input_example=input_example)
|
Loading…
Reference in New Issue
Block a user