Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MadryLab/robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewilyas committed Aug 21, 2019
2 parents 47d5e18 + 5698730 commit c7ea279
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 8 additions & 4 deletions robustness/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ def setup_store_with_metadata(args):
argparse object above for options.
'''
# Add git commit to args
repo = git.Repo(path=os.path.dirname(os.path.realpath(__file__)),
search_parent_directories=True)
git_commit = repo.head.object.hexsha
try:
repo = git.Repo(path=os.path.dirname(os.path.realpath(__file__)),
search_parent_directories=True)
git_commit = repo.head.object.hexsha
except git.exc.InvalidGitRepositoryError:
git_commit = 'pip_' + helpers.get_pip_version()
print(git_commit)
args.git_commit = git_commit

# Create the store
store = cox.store.Store(args.out_dir, args.exp_name)
args_dict = args.as_dict()
args_dict = args.__dict__
schema = cox.store.schema_from_dict(args_dict)
store.add_table('metadata', schema)
store['metadata'].append_row(args_dict)
Expand Down
10 changes: 9 additions & 1 deletion robustness/tools/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import dill
import os
from subprocess import Popen, PIPE
import pandas as pd
from PIL import Image
from . import constants
Expand Down Expand Up @@ -204,4 +205,11 @@ def restricted_label_mapping(classes, class_to_idx, ranges):
filtered_classes = list(mapping.keys()).sort()
return filtered_classes, mapping


def get_pip_version():
cmd = "pip show robustness 2> /dev/null | cat | head -n 2 "
cmd += "| tail -n 1 | sed 's/Version: //'"
process = Popen(cmd, stdout=PIPE, shell=True)
(output, err) = process.communicate()
exit_code = process.wait()
pip_version = output.strip().decode('UTF-8')
return pip_version

0 comments on commit c7ea279

Please sign in to comment.