This file contains hidden or 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
from PIL import Image | |
model = load_model(rev=selected_commit.hexsha) | |
uploaded_file = st.file_uploader("Upload an image") | |
if uploaded_file: | |
image = Image.open(uploaded_file) | |
image_name = uploaded_file.name | |
resized_image = image.resize(IMG_SIZE) |
This file contains hidden or 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
from pathlib import Path | |
import tensorflow as tf | |
# Warning: this is private internal dvc api, it may change with future version | |
import dvc.repo.get | |
ROOT_MODEL_CACHE_DIR = Path(".model_cache") | |
ROOT_MODEL_CACHE_DIR.mkdir(exist_ok=True) | |
@st.cache | |
def load_model(rev: str): |
This file contains hidden or 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
experiments = pd.DataFrame([ | |
{ | |
"hash": model_commit.hexsha, | |
"message": model_commit.message, | |
"committed_datetime": str(model_commit.committed_datetime), | |
"committer": str(model_commit.committer), | |
**MODELS_PARAMETERS[model_commit.hexsha], | |
**MODELS_EVALUATION_METRICS[model_commit.hexsha], | |
} | |
for model_commit in MODELS_COMMITS |
This file contains hidden or 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
import json | |
def _read_model_evaluation_metrics(rev: str) -> dict: | |
with dvc.api.open("data/evaluation/metrics.json", rev=rev) as file: | |
return json.load(file) | |
MODELS_EVALUATION_METRICS = { | |
commit.hexsha: _read_model_evaluation_metrics(model_rev=commit.hexsha) | |
for commit in MODELS_COMMITS | |
} |
This file contains hidden or 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
import yaml | |
def _read_train_params(rev: str) -> dict: | |
with git_open("dvc.lock", rev=rev) as file: | |
dvc_lock = yaml.safe_load(file) | |
return dvc_lock["stages"]["train"]["params"]["params.yaml"] | |
MODELS_PARAMETERS = { | |
commit.hexsha: _read_train_params(rev=commit.hexsha) | |
for commit in MODELS_COMMITS |
This file contains hidden or 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
FIRST_COMMIT = list(REPO.iter_commits())[-1] | |
@contextmanager | |
def git_open(path: str, rev: str): | |
commit = REPO.commit(rev) | |
# Hack to get the full blob data stream: compute diff with initial commit | |
diff = commit.diff(FIRST_COMMIT, str(path))[0] | |
yield diff.a_blob.data_stream |
This file contains hidden or 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
st.dataframe(disagree_predictions) | |
for _, row in disagree_predictions.iterrows(): | |
st.image( | |
row["image_path"], | |
caption=f"{row['image_name']}: A={row['predicted_label_x']}, B={row['predicted_label_y']} (true={row['true_label']})", | |
width=150, | |
) |
This file contains hidden or 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
predictions_a = load_predictions(rev=selected_commit_a.hexsha) | |
predictions_b = load_predictions(rev=selected_commit_b.hexsha) | |
disagree_predictions = pd.merge( | |
left=predictions_a.drop(columns=["prediction"]), | |
right=predictions_b.drop(columns=["true_label", "image_path", "prediction"]), | |
on="image_name", | |
).loc[lambda df: df.predicted_label_x != df.predicted_label_y] |
This file contains hidden or 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
selected_commit_a = st.selectbox( | |
"Choose commit A", | |
[commit for commit in MODELS_COMMITS], | |
format_func=lambda commit: f"{commit.hexsha[:6]} - {commit.message} - {commit.committed_datetime}", | |
) | |
selected_commit_b = st.selectbox( | |
"Choose commit B", | |
[commit for commit in MODELS_COMMITS], | |
format_func=lambda commit: f"{commit.hexsha[:6]} - {commit.message} - {commit.committed_datetime}", |
This file contains hidden or 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
import dvc.api | |
import pandas as pd | |
@st.cache | |
def load_predictions(rev: str) -> pd.DataFrame: | |
with dvc.api.open("data/evaluation/predictions.csv", rev=rev) as f: | |
return pd.read_csv(f) | |
selected_commit = ... # Use the commit selector introduced previous section |
NewerOlder