-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update .gitignore and remove unnecessary files and code
- Loading branch information
1 parent
a828a4f
commit bc2ec85
Showing
9 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ tf_training/mlruns/* | |
|
||
# saved models | ||
tf_training/tmp/* | ||
tf_serving/tmp/* | ||
|
||
# data | ||
data/* | ||
|
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions
13
tf_training/docker-compose.yml → tf_serving/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
version: '3.2' | ||
version: "3.2" | ||
services: | ||
tf_serving: | ||
ports: | ||
- '8501:8501' | ||
- "8501:8501" | ||
container_name: reviews_prediction | ||
environment: | ||
- MODEL_NAME=reviews_preds | ||
image: tensorflow/serving | ||
volumes: | ||
- type: bind | ||
source: ./tmp/swivel | ||
source: ./tmp/best_model/model/data/model | ||
target: /models/reviews_preds/1 | ||
networks: | ||
- app | ||
streamlit: | ||
build: ./app | ||
image: 3aak/streamlit | ||
ports: | ||
- '9000:9000' | ||
- "9000:9000" | ||
container_name: streamlit_ui | ||
volumes: | ||
- './app:/app' | ||
- "./app:/app" | ||
depends_on: | ||
- tf_serving | ||
command: streamlit run app.py --server.port=9000 --browser.serverAddress=0.0.0.0 | ||
networks: | ||
- app | ||
networks: | ||
app: | ||
external: | ||
name: app | ||
driver: bridge |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Select the best model from the MLflow experiment and save it to a directory"" | ||
""" | ||
|
||
import os | ||
|
||
import mlflow | ||
|
||
|
||
# Function to find the best model | ||
def get_best_model(experiment_name): | ||
"""Get the best model from the MLflow experiment""" | ||
runs = mlflow.search_runs(experiment_names=[experiment_name]) | ||
best_run = runs.sort_values("metrics.val_recall", ascending=False).iloc[0] | ||
print(f"best model: ", best_run["tags.mlflow.runName"]) | ||
return best_run | ||
|
||
|
||
def save_model(best_run, model_path="../tf_serving/tmp/best_model"): | ||
"""Save the best model to a directory""" | ||
# Model artifacts | ||
model_uri = best_run["artifact_uri"] + "/model" | ||
os.makedirs(model_path, exist_ok=True) | ||
mlflow.artifacts.download_artifacts(artifact_uri=model_uri, dst_path=model_path) | ||
|
||
|
||
def select_best_model(): | ||
"""Select the best model from the MLflow experiment and save it to a directory""" | ||
# MLflow server details | ||
mlflow.set_tracking_uri("http://localhost:5000") | ||
experiment_name = "Reviews_Classification" | ||
best_run = get_best_model(experiment_name) | ||
save_model(best_run) | ||
|
||
|
||
if __name__ == "__main__": | ||
select_best_model() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters