Skip to content

Instantly share code, notes, and snippets.

View AntoineToubhans's full-sized avatar

Toubi AntoineToubhans

View GitHub Profile
@AntoineToubhans
AntoineToubhans / check-git-branch-before-deploy.js
Created May 31, 2018 07:26
A tiny serverless plugin to check the current branch before deploy
const exec = require('child_process').exec;
class CheckGitBranchBeforeDeploy {
constructor (serverless, options) {
this.commands = {
deploy: {
lifecycleEvents: [
'resources',
]
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):
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)
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
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
}
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
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
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,
)
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]
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}",