diff --git a/avocado-mlflow.py b/avocado-mlflow.py index 71197f2..89d9df5 100644 --- a/avocado-mlflow.py +++ b/avocado-mlflow.py @@ -14,6 +14,7 @@ from tensorflow.keras.models import Model from tensorflow.keras.callbacks import EarlyStopping from keras.models import Sequential import mlflow +from mlflow.tracking import MlflowClient @@ -62,6 +63,11 @@ def my_main(epochs, batch_size): epochs = int(sys.argv[1]) if len(sys.argv) > 1 else 15 batch_size = int(sys.argv[2]) if len(sys.argv) > 2 else 16 +mlflow.set_tracking_uri("http://172.17.0.1:5000") +mlflow.set_experiment("s434742") +client = MlflowClient() + + with mlflow.start_run(): @@ -71,4 +77,6 @@ with mlflow.start_run(): mlflow.log_param("batch_size", batch_size) mlflow.log_metric("rmse", rmse) #mlflow.keras.log_model(model, 'avocado_model.h5') - mlflow.keras.log_model(keras_model=model, path='avocado_model', signature=infer_signature(X_train, y_train), input_example=X_train.iloc[0]) \ No newline at end of file + mlflow.keras.log_model(keras_model=model, path='avocado_model', registered_model_name="s434742", signature=infer_signature(X_train, y_train), input_example=X_train.iloc[0]) + mlflow.keras.save_model(keras_model=model, path='avocado_model', signature=infer_signature(X_train, y_train), input_example=X_train.iloc[0]) + diff --git a/predict-s434704.Jenkinsfile b/predict-s434704.Jenkinsfile new file mode 100644 index 0000000..aeff407 --- /dev/null +++ b/predict-s434704.Jenkinsfile @@ -0,0 +1,40 @@ +pipeline { + agent { + dockerfile true + } + + parameters { + string( + defaultValue: 'input_example.json', + description: 'Input name', + name: 'INPUT_EXAMPLE', + trim: false + ) + + buildSelector( + defaultSelector: lastSuccessful(), + description: 'Which build to use for copying artifacts for predict', + name: 'BUILD_SELECTOR_s434704') + } + + stages{ + + stage('copy artifacts from s434704') { + steps { + copyArtifacts filter: 'movies_on_streaming_platforms_model/**/*', fingerprintArtifacts: false, projectName: 's434704-training/master', selector: buildParameter('BUILD_SELECTOR_s434704') + } + } + + stage('predict data from s434704') { + steps { + script { + sh 'chmod +x predict-s434704.py' + sh 'python3 predict-s434704.py $INPUT_EXAMPLE' + } + } + } + + + + } + } \ No newline at end of file diff --git a/predict-s434704.py b/predict-s434704.py new file mode 100644 index 0000000..48fba75 --- /dev/null +++ b/predict-s434704.py @@ -0,0 +1,13 @@ +import json +import sys +import mlflow + +filename = sys.argv[1] + +model = mlflow.keras.load_model("movies_on_streaming_platforms_model") +path = 'movies_on_streaming_platforms_model/' + filename + +with open(path) as f: + data = json.load(f) + +model.predict(data['inputs']) \ No newline at end of file