Add MLFlow model generator && serving it
This commit is contained in:
parent
b82917a5d9
commit
925b5e71ce
@ -20,8 +20,14 @@ pipeline {
|
|||||||
sh "python3 sacred_exp.py"
|
sh "python3 sacred_exp.py"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
stage("Run MLFlow training"){
|
||||||
|
steps {
|
||||||
|
sh "python3 ml_model.py ${verbose} ${epochs}"
|
||||||
|
}
|
||||||
|
}
|
||||||
stage('Save trained model files') {
|
stage('Save trained model files') {
|
||||||
steps{
|
steps{
|
||||||
|
archiveArtifacts 'movies_on_streaming_platforms_model/**'
|
||||||
archiveArtifacts 'sacred_file/**'
|
archiveArtifacts 'sacred_file/**'
|
||||||
archiveArtifacts 'linear_regression.h5'
|
archiveArtifacts 'linear_regression.h5'
|
||||||
}
|
}
|
||||||
|
54
ml_model.py
Normal file
54
ml_model.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import tensorflow as tf
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
import mlflow
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from tensorflow import keras
|
||||||
|
from tensorflow.keras import layers
|
||||||
|
from tensorflow.keras.layers.experimental import preprocessing
|
||||||
|
|
||||||
|
arguments = sys.argv[1:]
|
||||||
|
|
||||||
|
verbose = int(arguments[0])
|
||||||
|
epochs = int(arguments[1])
|
||||||
|
|
||||||
|
# Wczytanie danych
|
||||||
|
train_data = pd.read_csv("./MoviesOnStreamingPlatforms_updated.train")
|
||||||
|
test_data = pd.read_csv("./MoviesOnStreamingPlatforms_updated.test")
|
||||||
|
|
||||||
|
# Stworzenie modelu
|
||||||
|
columns_to_use = ['Year', 'Runtime', 'Netflix']
|
||||||
|
train_X = tf.convert_to_tensor(train_data[columns_to_use])
|
||||||
|
train_Y = tf.convert_to_tensor(train_data[["IMDb"]])
|
||||||
|
|
||||||
|
test_X = tf.convert_to_tensor(test_data[columns_to_use])
|
||||||
|
test_Y = tf.convert_to_tensor(test_data[["IMDb"]])
|
||||||
|
|
||||||
|
normalizer = preprocessing.Normalization(input_shape=[3,])
|
||||||
|
normalizer.adapt(train_X)
|
||||||
|
|
||||||
|
model = keras.Sequential([
|
||||||
|
keras.Input(shape=(len(columns_to_use),)),
|
||||||
|
normalizer,
|
||||||
|
layers.Dense(30, activation='relu'),
|
||||||
|
layers.Dense(10, activation='relu'),
|
||||||
|
layers.Dense(25, activation='relu'),
|
||||||
|
layers.Dense(1)
|
||||||
|
])
|
||||||
|
|
||||||
|
model.compile(loss='mean_absolute_error',
|
||||||
|
optimizer=tf.keras.optimizers.Adam(0.001),
|
||||||
|
metrics=[tf.keras.metrics.RootMeanSquaredError()])
|
||||||
|
|
||||||
|
model.fit(train_X, train_Y, verbose=verbose, epochs=epochs)
|
||||||
|
|
||||||
|
signature = mlflow.models.signature.infer_signature(train_X.numpy(), model.predict(train_X.numpy()))
|
||||||
|
input_data = test_X
|
||||||
|
|
||||||
|
with mlflow.start_run():
|
||||||
|
mlflow.keras.save_model(model, "movies_on_streaming_platforms_model", input_example=input_data.numpy(), signature=signature)
|
||||||
|
|
||||||
|
|
15
mlruns/0/724dc0d672664057b760fe5f18801036/meta.yaml
Normal file
15
mlruns/0/724dc0d672664057b760fe5f18801036/meta.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
artifact_uri: file:///Volumes/seagate/ium_434704/mlruns/0/724dc0d672664057b760fe5f18801036/artifacts
|
||||||
|
end_time: 1621772380826
|
||||||
|
entry_point_name: ''
|
||||||
|
experiment_id: '0'
|
||||||
|
lifecycle_stage: active
|
||||||
|
name: ''
|
||||||
|
run_id: 724dc0d672664057b760fe5f18801036
|
||||||
|
run_uuid: 724dc0d672664057b760fe5f18801036
|
||||||
|
source_name: ''
|
||||||
|
source_type: 4
|
||||||
|
source_version: ''
|
||||||
|
start_time: 1621772379167
|
||||||
|
status: 3
|
||||||
|
tags: []
|
||||||
|
user_id: wj
|
@ -0,0 +1 @@
|
|||||||
|
b82917a5d90e071de9b67f2b6648be0353c54b62
|
@ -0,0 +1 @@
|
|||||||
|
ml_model.py
|
@ -0,0 +1 @@
|
|||||||
|
LOCAL
|
@ -0,0 +1 @@
|
|||||||
|
wj
|
20
movies_on_streaming_platforms_model/MLmodel
Normal file
20
movies_on_streaming_platforms_model/MLmodel
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
flavors:
|
||||||
|
keras:
|
||||||
|
data: data
|
||||||
|
keras_module: tensorflow.keras
|
||||||
|
keras_version: 2.5.0
|
||||||
|
save_format: tf
|
||||||
|
python_function:
|
||||||
|
data: data
|
||||||
|
env: conda.yaml
|
||||||
|
loader_module: mlflow.keras
|
||||||
|
python_version: 3.9.1
|
||||||
|
saved_input_example_info:
|
||||||
|
artifact_path: input_example.json
|
||||||
|
format: tf-serving
|
||||||
|
type: ndarray
|
||||||
|
signature:
|
||||||
|
inputs: '[{"type": "tensor", "tensor-spec": {"dtype": "float64", "shape": [-1, 3]}}]'
|
||||||
|
outputs: '[{"type": "tensor", "tensor-spec": {"dtype": "float32", "shape": [-1,
|
||||||
|
1]}}]'
|
||||||
|
utc_time_created: '2021-05-23 12:19:39.663838'
|
10
movies_on_streaming_platforms_model/conda.yaml
Normal file
10
movies_on_streaming_platforms_model/conda.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
channels:
|
||||||
|
- defaults
|
||||||
|
- conda-forge
|
||||||
|
dependencies:
|
||||||
|
- python=3.9.1
|
||||||
|
- pip
|
||||||
|
- pip:
|
||||||
|
- mlflow
|
||||||
|
- tensorflow==2.5.0-rc1
|
||||||
|
name: mlflow-env
|
@ -0,0 +1 @@
|
|||||||
|
tensorflow.keras
|
File diff suppressed because one or more lines are too long
BIN
movies_on_streaming_platforms_model/data/model/saved_model.pb
Normal file
BIN
movies_on_streaming_platforms_model/data/model/saved_model.pb
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
movies_on_streaming_platforms_model/data/save_format.txt
Normal file
1
movies_on_streaming_platforms_model/data/save_format.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
tf
|
1
movies_on_streaming_platforms_model/input_example.json
Normal file
1
movies_on_streaming_platforms_model/input_example.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user